Is there a better way to find out of a file or directory exists?


This seems a bit cumbersome

var fileExists = 
    new File(path).existsSync() || 
    new Directory(path).existsSync() || 
    new Link(path).existsSync() 

Is there a shorter or better way?


A shorter way is

import 'dart:io';

FileSystemEntity.typeSync(path) != FileSystemEntityType.notFound

See also

Answered By – Günter Zöchbauer

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *