Check if a file exists before loading it

In order to see whether or not a file exists in internal local storage of the app use:

import 'dart:io' as io;
var syncPath = await path;

// for a file
await io.File(syncPath).exists();
io.File(syncPath).existsSync();

// for a directory
await io.Directory(syncPath).exists();
io.Directory(syncPath).existsSync();

Leave a Comment