@@ -96,22 +96,12 @@ abstract class AssetBundle {
96
96
}
97
97
98
98
/// 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.
100
100
///
101
101
/// Implementations may cache the result, so a particular key should only be
102
102
/// used with one parser for the lifetime of the asset bundle.
103
103
Future <T > loadStructuredData <T >(String key, Future <T > Function (String value) parser);
104
104
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
-
115
105
/// If this is a caching asset bundle, and the given key describes a cached
116
106
/// asset, then evict the asset from the cache so that the next time it is
117
107
/// loaded, the cache will be reread from the asset bundle.
@@ -164,16 +154,6 @@ class NetworkAssetBundle extends AssetBundle {
164
154
return parser (await loadString (key));
165
155
}
166
156
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
-
177
157
// TODO(ianh): Once the underlying network logic learns about caching, we
178
158
// should implement evict().
179
159
@@ -193,7 +173,6 @@ abstract class CachingAssetBundle extends AssetBundle {
193
173
// TODO(ianh): Replace this with an intelligent cache, see https://github.com/flutter/flutter/issues/3568
194
174
final Map <String , Future <String >> _stringCache = < String , Future <String >> {};
195
175
final Map <String , Future <dynamic >> _structuredDataCache = < String , Future <dynamic >> {};
196
- final Map <String , Future <dynamic >> _structuredBinaryDataCache = < String , Future <dynamic >> {};
197
176
198
177
@override
199
178
Future <String > loadString (String key, { bool cache = true }) {
@@ -242,66 +221,16 @@ abstract class CachingAssetBundle extends AssetBundle {
242
221
return completer.future;
243
222
}
244
223
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
-
293
224
@override
294
225
void evict (String key) {
295
226
_stringCache.remove (key);
296
227
_structuredDataCache.remove (key);
297
- _structuredBinaryDataCache.remove (key);
298
228
}
299
229
300
230
@override
301
231
void clear () {
302
232
_stringCache.clear ();
303
233
_structuredDataCache.clear ();
304
- _structuredBinaryDataCache.clear ();
305
234
}
306
235
307
236
@override
@@ -343,7 +272,7 @@ class PlatformAssetBundle extends CachingAssetBundle {
343
272
bool debugUsePlatformChannel = false ;
344
273
assert (() {
345
274
// 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
347
276
// web presence. Override how assets are loaded in tests so that
348
277
// the old loader behavior that allows tests to load assets from
349
278
// the current package using the package prefix.
0 commit comments