[英]DecorationImage doesn't show the image - Flutter
I couldn't find anything related to this, so I guess I am doing something very wrong.我找不到与此相关的任何内容,所以我想我做错了。 I am trying to display a
DecorationImage
inside BoxDecoration
, but nothing shows on my screen at all.我试图在
BoxDecoration
中显示一个DecorationImage
,但我的屏幕上根本没有显示任何内容。
I try to show the related asset with Image.asset('assets\\test.png');
我尝试用
Image.asset('assets\\test.png');
显示相关资产and that works with no problem.这没有问题。 I have tried to put things like
AssetImage
or FileImage
inside DecorationImage
, but it seems like none of them work for me.我试图将
AssetImage
或FileImage
类的东西放在DecorationImage
中,但似乎它们都不适合我。
My code is basically as below:我的代码基本上如下:
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets\\test.png'),
fit: BoxFit.cover,
),
),
),
],
),
)
);
What should I do for my test.png
to show?我应该怎么做才能让我的
test.png
显示出来? Currently I just see an empty screen.目前我只看到一个空屏幕。
You need to give width
and height
to your Container
, like this你需要给你的
Container
width
和height
,就像这样
new Container(
height: 100,
width: 100,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets\\test.png'),
fit: BoxFit.cover,
),
),
),
just wrong way.. use this => "/" not this => "\"只是错误的方式..使用这个=>“/”不是这个=>“\”
image: DecorationImage( image: AssetImage("lib/assets/images/aksam_gece.png"), fit: BoxFit.fill, ),
also check pubspec path还要检查 pubspec 路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.