I'm seeing a similar error to this mentioned by @Nazacheres.
When using both the dev and beta channel of flutter. I haven't checked on stable yet.
Flutter 1.16.4-pre.86 • channel dev • https://github.com/flutter/flutter
Framework • revision a8b3d1b74f (3 days ago) • 2020-04-02 15:40:37 -0700
Engine • revision f56e678e7f
Tools • Dart 2.8.0 (build 2.8.0-dev.19.0 fae35fca47)
My dart code looks like this.
Future<void> main() async {
await precachePicture(
ExactAssetPicture(SvgPicture.svgStringDecoder, SvgAsset.logo.withText),
null,
);
runApp(const SpinnyBoxApp());
// Loads the local settings for the device.
await SpinnyBoxSettings.loadSettings();
}
It crashes on the await precachePicture line with the following error log. _Click to expand the accordion._
Error Log
E/flutter (24782): Tried calling: dependOnInheritedWidgetOfExactType<DefaultAssetBundle>()
E/flutter (24782): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (24782): #1 DefaultAssetBundle.of
package:flutter/…/widgets/basic.dart:5485
E/flutter (24782): #2 createLocalPictureConfiguration
package:flutter_svg/src/picture_provider.dart:48
E/flutter (24782): #3 precachePicture
package:flutter_svg/svg.dart:138
E/flutter (24782): #4 main
package:spinny_box/main.dart:18
E/flutter (24782): #5 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:241:25)
E/flutter (24782): #6 _rootRun (dart:async/zone.dart:1184:13)
E/flutter (24782): #7 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (24782): #8 _runZoned (dart:async/zone.dart:1619:10)
E/flutter (24782): #9 runZonedGuarded (dart:async/zone.dart:1608:12)
E/flutter (24782): #10 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:233:5)
E/flutter (24782): #11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter (24782): #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (24782):
Ahhh. Null won't work here.
precachePicture needs to be updated to handle this.
Fixed in v0.17.4
@dnfield Awesome work, just what I needed!
One question: How can you load multiple assets-images at once?
Now, my main looks like this:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await precachePicture(
ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/images/Welcome_carousel_1.svg'),
null,
);
await precachePicture(
ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/images/Welcome_carousel_2.svg'),
null,
);
await precachePicture(
ExactAssetPicture(SvgPicture.svgStringDecoder, 'assets/images/Welcome_carousel_3.svg'),
null,
);
runApp(BrilliantButtonsApp());
}
Keep up the good work.
That's basically it. You could refactor that into a method that just takes the strings I suppose
For someone who doesn't like manually call precachePicture per asset:
await Future.wait(
[
'assets/images/Welcome_carousel_1.svg',
'assets/images/Welcome_carousel_2.svg',
'assets/images/Welcome_carousel_3.svg',
].map(
(assetName) => precachePicture(
ExactAssetPicture(SvgPicture.svgStringDecoder, assetName),
null,
),
),
);
Most helpful comment
@dnfield Awesome work, just what I needed!
One question: How can you load multiple assets-images at once?
Now, my main looks like this:
Keep up the good work.