Flutter read all files from asset folder

后端 未结 2 1619
走了就别回头了
走了就别回头了 2021-02-06 06:59

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

Now I want to read the names of all the fold

相关标签:
2条回答
  • 2021-02-06 07:43

    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'));
    
    0 讨论(0)
  • 2021-02-06 07:43

    The easiest way to do this is, open your pubspec.yaml and in the assets line, change it as given below - just add the entire folder.

    assets:
      - assets/
    

    This will add all the folders and files in the asset folders.

    0 讨论(0)
提交回复
热议问题