-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
When it comes to validating and parsing asset manifests for both the "regular" asset manifest and the asset manifests of deferred components, there is nearly-duplicate code.
Code example
Code from parsing the regular asset manifest:
flutter/packages/flutter_tools/lib/src/flutter_manifest.dart
Lines 314 to 333 in 99c7e9f
| late final List<Uri> assets = _computeAssets(); | |
| List<Uri> _computeAssets() { | |
| final List<Object?>? assets = _flutterDescriptor['assets'] as List<Object?>?; | |
| if (assets == null) { | |
| return const <Uri>[]; | |
| } | |
| final List<Uri> results = <Uri>[]; | |
| for (final Object? asset in assets) { | |
| if (asset is! String || asset == '') { | |
| _logger.printError('Asset manifest contains a null or empty uri.'); | |
| continue; | |
| } | |
| try { | |
| results.add(Uri(pathSegments: asset.split('/'))); | |
| } on FormatException { | |
| _logger.printError('Asset manifest contains invalid uri: $asset.'); | |
| } | |
| } | |
| return results; | |
| } |
Code from parsing deferred component manifests:
flutter/packages/flutter_tools/lib/src/flutter_manifest.dart
Lines 235 to 250 in 99c7e9f
| final List<Object?>? assets = component['assets'] as List<Object?>?; | |
| if (assets == null) { | |
| assetsUri = const <Uri>[]; | |
| } else { | |
| for (final Object? asset in assets) { | |
| if (asset is! String || asset == '') { | |
| _logger.printError('Deferred component asset manifest contains a null or empty uri.'); | |
| continue; | |
| } | |
| try { | |
| assetsUri.add(Uri.parse(asset)); | |
| } on FormatException { | |
| _logger.printError('Asset manifest contains invalid uri: $asset.'); | |
| } | |
| } | |
| } |
For context, #132985 wishes to augment the grammar for the assets sections of pubspec.yaml. This duplicate logic has made this change more difficult to implement1.
Footnotes
-
Fun fact: the dart SDK also contains logic for validating asset declarations 🙃 . ↩