As per the Flutter docs I'm trying to use the DecoratedBox to load a fullscreen image as the background image for a Container.
my pubspec.yaml contains the relevant definition for an embedded asset:
flutter:
uses-material-design: true
assets:
- assets/background.png
and the widget.dart tries to fill the background of a new Container as prescribed:
@override
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(
color: Colors.purple,
image : new DecorationImage(
image: new ExactAssetImage('assets/background.png'),
fit: BoxFit.cover,
),
),
),
}
But I get the following error:
Unable to load asset: assets/background.png
Image provider: ExactAssetImage(name: "assets/background.png", scale: 1.0, bundle: null)
Clearly the bundle is not resolving correctly. Does anyone have an idea of what exactly I'm doing wrong here?
It works for me. A few things to double check:
AssetImage
instead of ExactAssetImage
Stack
would be fine, but a Column
would cause it to be 0x0 if it has no intrinsic size or child)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With