Reputation: 11
in dart enter image description here
in flutter enter image description here
add file in pubspec.yaml enter image description here
I want to check exists file in flutter. Where do I need to modify the code?
Upvotes: 0
Views: 523
Reputation: 12673
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");
}
Upvotes: 1