Add API for discovering assets (#118410)
* add asset manifest bin loading and asset manifest api * use new api for image resolution * remove upfront smc data casting * fix typecasting issue * remove unused import * fix tests * lints * lints * fix import * revert image resolution changes * Update image_resolution_test.dart * Update decode_and_parse_asset_manifest.dart * make targetDevicePixelRatio optional * Update packages/flutter/lib/src/services/asset_manifest.dart Co-authored-by: Jonah Williams <jonahwilliams@google.com> * Update packages/flutter/lib/src/services/asset_manifest.dart Co-authored-by: Jonah Williams <jonahwilliams@google.com> * fix immutable not being imported * return List in AssetManifest methods, fix annotation import * simplify onError callback * make AssetManifest methods abstract instead of throwing UnimplementedError * simplify AssetVariant.key docstring * tweak _AssetManifestBin docstring * make AssetManifest and AssetVariant doc strings more specific * use List.of instead of List.from for type-safety * adjust import * change _AssetManifestBin comment from doc comment to normal comment * revert to callback function for onError in loadStructuredBinaryData * add more to the docstring of AssetManifest.listAssets and AssetVariant.key * add tests for CachingAssetBundle caching behavior * add simple test to ensure loadStructuredBinaryData correctly calls load * Update asset_manifest.dart * update docstring for AssetManifest.getAssetVariants * rename getAssetVariants, have it include main asset * rename isMainAsset field of AssetMetadata to main * (slightly) shorten name of describeAssetAndVariants * rename describeAssetVariants back to getAssetVariants * add tests for TestAssetBundle * nits * fix typo in docstring * remove no longer necessary non-null asserts Co-authored-by: Jonah Williams <jonahwilliams@google.com>
This commit is contained in:
@@ -2,10 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart' show PlatformAssetBundle;
|
||||
import 'package:flutter/services.dart' show AssetManifest, PlatformAssetBundle, rootBundle;
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../common.dart';
|
||||
@@ -18,16 +15,12 @@ void main() async {
|
||||
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final Stopwatch watch = Stopwatch();
|
||||
final PlatformAssetBundle bundle = PlatformAssetBundle();
|
||||
final PlatformAssetBundle bundle = rootBundle as PlatformAssetBundle;
|
||||
|
||||
final ByteData assetManifestBytes = await bundle.load('money_asset_manifest.json');
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIterations; i++) {
|
||||
await AssetManifest.loadFromAssetBundle(bundle);
|
||||
bundle.clear();
|
||||
final String json = utf8.decode(assetManifestBytes.buffer.asUint8List());
|
||||
// This is a test, so we don't need to worry about this rule.
|
||||
// ignore: invalid_use_of_visible_for_testing_member
|
||||
await AssetImage.manifestParser(json);
|
||||
}
|
||||
watch.stop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user