can't check exists file in flutter but can check exists file in dart

Viewed 25
1 Answers

Try this:

Future<bool> assetExists(String path) async{
 try{
   await rootBundle.loadString(path);
   return true;
 } catch (e){
   return false;
 }
}

Then you can use the method like so:

String path = 'images/nocolor.png';
bool fileExists = await assetExists(path);
if (fileExists) {
   print ("have file");
}else{
   print ("on file");
}
Related