resolveKey method

String resolveKey(
  1. String sourcePath, {
  2. String? package,
})

Resolves sourcePath (relative to the owning package's root, with or without the .glb/.fsceneb extension) to exactly one scene asset key.

Implementation

String resolveKey(String sourcePath, {String? package}) {
  final id = _sceneId(sourcePath);
  final matches = _entries
      .where(
        (entry) =>
            entry.sceneId == id &&
            (package == null || entry.package == package),
      )
      .toList();
  if (matches.isEmpty) {
    throw StateError(
      'No generated .fsceneb for source "$sourcePath" was found. '
      '${generatedAssetFixHint('scenes')}',
    );
  }
  if (matches.length > 1) {
    final choices = matches.map((match) => match.package).join(', ');
    throw StateError(
      'Multiple generated .fsceneb files for source "$sourcePath" were found '
      'in packages: $choices. Pass package to disambiguate.',
    );
  }
  return matches.single.assetKey;
}