【发布时间】:2017-10-07 20:56:53
【问题描述】:
根据Flutter docs,我正在尝试使用 DecoratedBox 加载全屏图像作为容器的背景图像。
我的 pubspec.yaml 包含嵌入式资产的相关定义:
flutter:
uses-material-design: true
assets:
- assets/background.png
widget.dart 会按照规定尝试填充新 Container 的背景:
@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,
),
),
),
}
但我收到以下错误:
Unable to load asset: assets/background.png
Image provider: ExactAssetImage(name: "assets/background.png", scale: 1.0, bundle: null)
显然捆绑包没有正确解析。有谁知道我在这里到底做错了什么?
【问题讨论】: