Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Now I want to read the names of all the folders that are in the tabs folder and all the files that are in each subfolder of the tabs folder, i.e. folders that are named as sound 1, sound 2, sound 3 .....

In simple words, I want to read names of all files and folders that are in my assets folder. Please Anyone help. Thanks,

like image 365
Taha Malik Avatar asked Nov 06 '19 23:11

Taha Malik


People also ask

How do I read all files in a folder in flutter?

To list all the files or folders, you have to use flutter_file_manager, path, and path_provider_ex flutter package. Add the following lines in your pubspec. yaml file to add this package in your dependency. Add read / write permissions in your android/app/src/main/AndroidManifest.


1 Answers

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'));
like image 118
Spatz Avatar answered Oct 07 '22 00:10

Spatz