根据Flutter 文档,我尝试使用 DecoratedBox 加载全屏图像作为容器的背景图像。
我的 pubspec.yaml 包含嵌入式资产的相关定义:
flutter:
uses-material-design: true
assets:
- assets/background.png
Run Code Online (Sandbox Code Playgroud)
并且 widget.dart 尝试按照规定填充新容器的背景:
@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,
),
),
),
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Unable to load asset: assets/background.png
Image provider: ExactAssetImage(name: "assets/background.png", scale: 1.0, bundle: null)
Run Code Online (Sandbox Code Playgroud)
显然,包没有正确解析。有没有人知道我在这里做错了什么?
这个对我有用。需要仔细检查的几件事:
AssetImage
代替ExactAssetImage
Stack
可以,但Column
如果它没有固有大小或孩子,a会导致它是 0x0) 归档时间: |
|
查看次数: |
7109 次 |
最近记录: |