Flutter-将图像设置为材质的背景

时间:2019-04-01 07:19:27

标签: dart flutter

我正在尝试创建一个以图像为背景的return Material

这是我的代码:

    return Material(
        //I tried add this code 
        child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              fit: BoxFit.fill,
              image: AssetImage('assets/img1.png'))
        ),
          color: Colors.white,
        //======================
    child: Stack(
            children: <Widget>[
              Container(
              ....
              text("Some text");)
      ]
    )

如何为return Material设置背景?

1 个答案:

答案 0 :(得分:0)

您可以使用容器并在装饰中显示图像

 Material(
    //I tried add this code
    child: Container(
    decoration: BoxDecoration(
        image: DecorationImage(
        fit: BoxFit.fill,
        image: AssetImage('assets/img1.png'))),
    color: Colors.white,
    ))