@@ -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.
0 commit comments