Skip to content

Latest commit

 

History

History
40 lines (22 loc) · 1.38 KB

README.md

File metadata and controls

40 lines (22 loc) · 1.38 KB

Flutter_listing_assets

Flutter - Listing files in assets dynamically

With this code you will get list of files in assets with Dart code for Flutter.

First you need to configure your pubspec.yaml file with assets.

For this resources ->

The pubspec.yaml ->

You should read de file AssetManifest.json (contains path of all assets files include in pubspec.yaml) and filter the text.

var assetsFile = await DefaultAssetBundle.of(context).loadString('AssetManifest.json');
final Map<String, dynamic> manifestMap = json.decode(assetsFile);

For example for filter the .jpg ->

List<String> listMp3 =
    manifestMap.keys.where((String key) => key.contains('.mp3')).toList();

The return -> [assets/perfect_squat.jpg, assets/slav_boss.jpg]

This repository has an example of how load from assets the list files and load the existing images. You have the code in main.dart and the resources in assets/.

Android example:

Using in apps I make for strattonapps.com