load static method
Loads every generated flutter_scene .fmat bundle index the app ships,
whether it arrived as a data asset or through the generated tree.
Implementation
static Future<FmatMaterialRegistry> load({
AssetBundle? bundle,
Iterable<String>? assetKeys,
}) async {
final assetBundle = bundle ?? rootBundle;
final keys = assetKeys ?? await _loadAssetManifestKeys(assetBundle);
final indexKeys = keys.where(isFmatIndexAssetKey).toList()..sort();
if (assetKeys == null) {
// A bundle index recorded in the generated tree, keyed by the bundle name
// rather than by a data-asset path.
final generated = await loadGeneratedAssetIndex(bundle);
for (final match in generated.entriesOf(GeneratedAssetFamily.material)) {
if (match.entry.id.contains('#')) continue;
indexKeys.add(match.key);
}
}
final indexes = <FmatMaterialBundleIndex>[];
for (final key in indexKeys) {
// Evict so a hot reload re-reads a regenerated index.
if (kDebugMode) assetBundle.evict(key);
final json = jsonDecode(await assetBundle.loadString(key));
final index = FmatMaterialBundleIndex.fromJson(
(json as Map).cast<String, Object?>(),
assetKey: key,
);
// The app's own tree comes first, so its copy of a bundle a dependency
// also ships (flutter_scene's physical materials) wins.
if (indexes.any(
(other) =>
other.package == index.package &&
other.bundleName == index.bundleName,
)) {
continue;
}
indexes.add(index);
}
return FmatMaterialRegistry._(assetBundle, indexes);
}