Search code examples
androidiosflutterdartcross-platform

Flutter read all files from asset folder


I have an assets folder in which I have a tab folder and then a list of folders and each folder contains some files:

enter image description here

I want to read the names of all the files and folders that are in my assets folder. How do I do that?


Solution

  • Even if you specified only asset folders in pubspec.yaml, the flutter compiler lists all files from these folders in AssetManifest.json file. All we have to do is read this file:

    final manifestJson = await DefaultAssetBundle.of(context).loadString('AssetManifest.json');
    final images = json.decode(manifestJson).keys.where((String key) => key.startsWith('assets/images'));