即使在pubspec.yaml
中仅指定了资源文件夹,Flutter 编译器也会在AssetManifest.json
文件中列出这些文件夹中的所有文件.我们要做的就是阅读这个文件:
final manifestJson = await DefaultAssetBundle.of(context).loadString('AssetManifest.json');
final images = json.decode(manifestJson).keys.where((String key) => key.startsWith('assets/images'));