Correct handling of assets when no main asset is present (#11564)

This commit is contained in:
Hans Muller
2017-08-09 16:04:57 -07:00
committed by GitHub
parent 5ee8390e9c
commit 680d581db7
3 changed files with 81 additions and 7 deletions

View File

@@ -98,6 +98,10 @@ class AssetBundle {
final PackageMap packageMap = new PackageMap(packagesPath);
// The _assetVariants map contains an entry for each asset listed
// in the pubspec.yaml file's assets and font and sections. The
// value of each image asset is a list of resolution-specific "variants",
// see _AssetDirectoryCache.
final Map<_Asset, List<_Asset>> assetVariants = _parseAssets(
packageMap,
manifestDescriptor,
@@ -112,14 +116,24 @@ class AssetBundle {
manifestDescriptor.containsKey('uses-material-design') &&
manifestDescriptor['uses-material-design'];
// Save the contents of each image, image variant, and font
// asset in entries.
for (_Asset asset in assetVariants.keys) {
if (!asset.assetFileExists && assetVariants[asset].isEmpty) {
printStatus('Error detected in pubspec.yaml:', emphasis: true);
printError('No file or variants found for $asset.\n');
return 1;
}
if (asset.assetFileExists)
entries[asset.assetEntry] = new DevFSFileContent(asset.assetFile);
// The file name for an asset's "main" entry is whatever appears in
// the pubspec.yaml file. The main entry's file must always exist for
// font assets. It need not exist for an image if resolution-specific
// variant files exist. An image's main entry is treated the same as a
// "1x" resolution variant and if both exist then the explicit 1x
// variant is preferred.
if (asset.assetFileExists) {
assert(!assetVariants[asset].contains(asset));
assetVariants[asset].insert(0, asset);
}
for (_Asset variant in assetVariants[asset]) {
assert(variant.assetFileExists);
entries[variant.assetEntry] = new DevFSFileContent(variant.assetFile);