Skip to content

DiMiTriFrog/Flutter_listing_assets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Flutter - Listing resource files in assets dynamically

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages