resolve method
Resolves sourcePath (the .fmat source path relative to the owning
package's root, with or without the .fmat extension) to exactly one
generated bundle/index entry.
Keying by source path (rather than material name) means two materials that share a name in different directories do not collide.
Implementation
FmatMaterialResolution resolve(
String sourcePath, {
String? package,
String? bundleName,
}) {
final id = _materialId(sourcePath);
final matches = <FmatMaterialResolution>[];
for (final index in _indexes) {
if (package != null && index.package != package) {
continue;
}
if (bundleName != null && index.bundleName != bundleName) {
continue;
}
for (final entry in index.materials.values) {
final source = entry.source;
if (source != null && _materialId(source) == id) {
matches.add(FmatMaterialResolution(index: index, entry: entry));
}
}
}
if (matches.isEmpty) {
throw StateError(
'No DataAssets-backed .fmat material for source "$sourcePath" was '
'found. Run `dart run flutter_scene:init`, enable Dart data assets on '
'a supported Flutter master build, and rebuild the app.',
);
}
if (matches.length > 1) {
final choices = matches
.map((match) => '${match.index.package}/${match.index.bundleName}')
.join(', ');
throw StateError(
'Multiple DataAssets-backed .fmat materials for source "$sourcePath" '
'were found: $choices. Pass package and/or bundleName to disambiguate.',
);
}
return matches.single;
}