我正在尝试创建一个类别卡,并将图像设置为子容器小部件的背景,但图像不会显示在容器上
Container job1category(String imgpath, String name, String nikename) {
return Container(
width: 170,
child: Card(
child: Wrap(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(imgpath),
fit: BoxFit.cover
)
),
child: null
),
ListTile(
title: Text(name),
subtitle: Text(nikename),
),
],
),
),
);
}
请试试这个,
Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('img/bg.jpg'),fit: BoxFit.cover)),
child: ...,
)
您可以简单地将图像添加为子项并设置属性填充。
Container(child:Image.network('https://thenypost.files.wordpress.com/2014/01/dogs1.jpg',fit:fil),)
您甚至可以设置容器的容量和高度。希望这可以帮助。