@@ -81,9 +81,6 @@ abstract class AssetBundle {
8181 /// isolate to avoid jank on the main thread.
8282 Future <String > loadString (String key, { bool cache = true }) async {
8383 final ByteData data = await load (key);
84- if (data == null ) {
85- throw FlutterError ('Unable to load asset: $key ' );
86- }
8784 // 50 KB of data should take 2-3 ms to parse on a Moto G4, and about 400 μs
8885 // on a Pixel 4.
8986 if (data.lengthInBytes < 50 * 1024 ) {
@@ -139,7 +136,7 @@ class NetworkAssetBundle extends AssetBundle {
139136 final HttpClientResponse response = await request.close ();
140137 if (response.statusCode != HttpStatus .ok) {
141138 throw FlutterError .fromParts (< DiagnosticsNode > [
142- ErrorSummary ( 'Unable to load asset: $ key ' ),
139+ _errorSummaryWithKey ( key),
143140 IntProperty ('HTTP status code' , response.statusCode),
144141 ]);
145142 }
@@ -255,7 +252,10 @@ class PlatformAssetBundle extends CachingAssetBundle {
255252 final ByteData ? asset =
256253 await ServicesBinding .instance.defaultBinaryMessenger.send ('flutter/assets' , encoded.buffer.asByteData ());
257254 if (asset == null ) {
258- throw FlutterError ('Unable to load asset: $key ' );
255+ throw FlutterError .fromParts (< DiagnosticsNode > [
256+ _errorSummaryWithKey (key),
257+ ErrorDescription ('The asset does not exist or has empty data.' ),
258+ ]);
259259 }
260260 return asset;
261261 }
@@ -284,8 +284,11 @@ class PlatformAssetBundle extends CachingAssetBundle {
284284 }
285285 try {
286286 return await ui.ImmutableBuffer .fromAsset (key);
287- } on Exception {
288- throw FlutterError ('Unable to load asset: $key .' );
287+ } on Exception catch (e) {
288+ throw FlutterError .fromParts (< DiagnosticsNode > [
289+ _errorSummaryWithKey (key),
290+ ErrorDescription (e.toString ()),
291+ ]);
289292 }
290293 }
291294}
@@ -294,6 +297,10 @@ AssetBundle _initRootBundle() {
294297 return PlatformAssetBundle ();
295298}
296299
300+ ErrorSummary _errorSummaryWithKey (String key) {
301+ return ErrorSummary ('Unable to load asset: "$key ".' );
302+ }
303+
297304/// The [AssetBundle] from which this application was loaded.
298305///
299306/// The [rootBundle] contains the resources that were packaged with the
0 commit comments