Skip to content

Commit a04ab71

Browse files
Revert "Add API for discovering assets (#118410)" (#119273)
This reverts commit 2b8f2d0.
1 parent 2b8f2d0 commit a04ab71

File tree

6 files changed

+14
-358
lines changed

6 files changed

+14
-358
lines changed

dev/benchmarks/microbenchmarks/lib/foundation/decode_and_parse_asset_manifest.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/services.dart' show AssetManifest, PlatformAssetBundle, rootBundle;
5+
import 'dart:convert';
6+
7+
import 'package:flutter/foundation.dart';
8+
import 'package:flutter/services.dart' show PlatformAssetBundle;
69
import 'package:flutter/widgets.dart';
710

811
import '../common.dart';
@@ -15,12 +18,16 @@ void main() async {
1518
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
1619
WidgetsFlutterBinding.ensureInitialized();
1720
final Stopwatch watch = Stopwatch();
18-
final PlatformAssetBundle bundle = rootBundle as PlatformAssetBundle;
21+
final PlatformAssetBundle bundle = PlatformAssetBundle();
1922

23+
final ByteData assetManifestBytes = await bundle.load('money_asset_manifest.json');
2024
watch.start();
2125
for (int i = 0; i < _kNumIterations; i++) {
22-
await AssetManifest.loadFromAssetBundle(bundle);
2326
bundle.clear();
27+
final String json = utf8.decode(assetManifestBytes.buffer.asUint8List());
28+
// This is a test, so we don't need to worry about this rule.
29+
// ignore: invalid_use_of_visible_for_testing_member
30+
await AssetImage.manifestParser(json);
2431
}
2532
watch.stop();
2633

packages/flutter/lib/services.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
library services;
1212

1313
export 'src/services/asset_bundle.dart';
14-
export 'src/services/asset_manifest.dart';
1514
export 'src/services/autofill.dart';
1615
export 'src/services/binary_messenger.dart';
1716
export 'src/services/binding.dart';

packages/flutter/lib/src/services/asset_bundle.dart

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,12 @@ abstract class AssetBundle {
9696
}
9797

9898
/// Retrieve a string from the asset bundle, parse it with the given function,
99-
/// and return that function's result.
99+
/// and return the function's result.
100100
///
101101
/// Implementations may cache the result, so a particular key should only be
102102
/// used with one parser for the lifetime of the asset bundle.
103103
Future<T> loadStructuredData<T>(String key, Future<T> Function(String value) parser);
104104

105-
/// Retrieve [ByteData] from the asset bundle, parse it with the given function,
106-
/// and return that function's result.
107-
///
108-
/// Implementations may cache the result, so a particular key should only be
109-
/// used with one parser for the lifetime of the asset bundle.
110-
Future<T> loadStructuredBinaryData<T>(String key, FutureOr<T> Function(ByteData data) parser) async {
111-
final ByteData data = await load(key);
112-
return parser(data);
113-
}
114-
115105
/// If this is a caching asset bundle, and the given key describes a cached
116106
/// asset, then evict the asset from the cache so that the next time it is
117107
/// loaded, the cache will be reread from the asset bundle.
@@ -164,16 +154,6 @@ class NetworkAssetBundle extends AssetBundle {
164154
return parser(await loadString(key));
165155
}
166156

167-
/// Retrieve [ByteData] from the asset bundle, parse it with the given function,
168-
/// and return the function's result.
169-
///
170-
/// The result is not cached. The parser is run each time the resource is
171-
/// fetched.
172-
@override
173-
Future<T> loadStructuredBinaryData<T>(String key, FutureOr<T> Function(ByteData data) parser) async {
174-
return parser(await load(key));
175-
}
176-
177157
// TODO(ianh): Once the underlying network logic learns about caching, we
178158
// should implement evict().
179159

@@ -193,7 +173,6 @@ abstract class CachingAssetBundle extends AssetBundle {
193173
// TODO(ianh): Replace this with an intelligent cache, see https://github.com/flutter/flutter/issues/3568
194174
final Map<String, Future<String>> _stringCache = <String, Future<String>>{};
195175
final Map<String, Future<dynamic>> _structuredDataCache = <String, Future<dynamic>>{};
196-
final Map<String, Future<dynamic>> _structuredBinaryDataCache = <String, Future<dynamic>>{};
197176

198177
@override
199178
Future<String> loadString(String key, { bool cache = true }) {
@@ -242,66 +221,16 @@ abstract class CachingAssetBundle extends AssetBundle {
242221
return completer.future;
243222
}
244223

245-
/// Retrieve bytedata from the asset bundle, parse it with the given function,
246-
/// and return the function's result.
247-
///
248-
/// The result of parsing the bytedata is cached (the bytedata itself is not).
249-
/// For any given `key`, the `parser` is only run the first time.
250-
///
251-
/// Once the value has been parsed, the future returned by this function for
252-
/// subsequent calls will be a [SynchronousFuture], which resolves its
253-
/// callback synchronously.
254-
@override
255-
Future<T> loadStructuredBinaryData<T>(String key, FutureOr<T> Function(ByteData data) parser) {
256-
if (_structuredBinaryDataCache.containsKey(key)) {
257-
return _structuredBinaryDataCache[key]! as Future<T>;
258-
}
259-
260-
// load can return a SynchronousFuture in certain cases, like in the
261-
// flutter_test framework. So, we need to support both async and sync flows.
262-
Completer<T>? completer; // For async flow.
263-
SynchronousFuture<T>? result; // For sync flow.
264-
265-
load(key)
266-
.then<T>(parser)
267-
.then<void>((T value) {
268-
result = SynchronousFuture<T>(value);
269-
if (completer != null) {
270-
// The load and parse operation ran asynchronously. We already returned
271-
// from the loadStructuredBinaryData function and therefore the caller
272-
// was given the future of the completer.
273-
completer.complete(value);
274-
}
275-
}, onError: (Object error, StackTrace stack) {
276-
completer!.completeError(error, stack);
277-
});
278-
279-
if (result != null) {
280-
// The above code ran synchronously. We can synchronously return the result.
281-
_structuredBinaryDataCache[key] = result!;
282-
return result!;
283-
}
284-
285-
// Since the above code is being run asynchronously and thus hasn't run its
286-
// `then` handler yet, we'll return a completer that will be completed
287-
// when the handler does run.
288-
completer = Completer<T>();
289-
_structuredBinaryDataCache[key] = completer.future;
290-
return completer.future;
291-
}
292-
293224
@override
294225
void evict(String key) {
295226
_stringCache.remove(key);
296227
_structuredDataCache.remove(key);
297-
_structuredBinaryDataCache.remove(key);
298228
}
299229

300230
@override
301231
void clear() {
302232
_stringCache.clear();
303233
_structuredDataCache.clear();
304-
_structuredBinaryDataCache.clear();
305234
}
306235

307236
@override
@@ -343,7 +272,7 @@ class PlatformAssetBundle extends CachingAssetBundle {
343272
bool debugUsePlatformChannel = false;
344273
assert(() {
345274
// dart:io is safe to use here since we early return for web
346-
// above. If that code is changed, this needs to be guarded on
275+
// above. If that code is changed, this needs to be gaurded on
347276
// web presence. Override how assets are loaded in tests so that
348277
// the old loader behavior that allows tests to load assets from
349278
// the current package using the package prefix.

packages/flutter/lib/src/services/asset_manifest.dart

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)