如何将图像作为容器窗口小部件的背景图像?

问题描述 投票:0回答:2

我正在尝试创建一个类别卡,并将图像设置为子容器小部件的背景,但图像不会显示在容器上

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),
      ),
    ],
  ),
),
);
}
dart flutter
2个回答
1
投票

请试试这个,

Container(
      width: double.infinity,
      height: double.infinity,
      decoration: BoxDecoration(
          image: DecorationImage(image: AssetImage('img/bg.jpg'),fit: BoxFit.cover)),
      child: ...,
    )

0
投票

您可以简单地将图像添加为子项并设置属性填充。

Container(child:Image.network('https://thenypost.files.wordpress.com/2014/01/dogs1.jpg',fit:fil),)

您甚至可以设置容器的容量和高度。希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.