如何在flutter中为图像背景指定图像背景

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

我想知道如何添加一个图像,作为我的翻转卡中的列的背景。

我想添加图像的代码如下所示(从子列新列到结尾):

 FlipCard(
            direction: FlipDirection.HORIZONTAL, // default
            front: Container(
              decoration: new BoxDecoration(
                border: new Border.all(color: Colors.black),
                borderRadius: BorderRadius.circular(10.0),
              ),
              margin: EdgeInsets.all(10.0),
              child: new Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  new Column(
                    children: <Widget>[
                      new Container(
                          margin: EdgeInsets.all(10),
                          width: 190.0,
                          height: 190.0,
                          decoration: new BoxDecoration(
                              shape: BoxShape.circle,
                              border: new Border.all(color: Colors.black),
                              image: new DecorationImage(
                                  fit: BoxFit.fill,
                                  image: new NetworkImage(
                                      "https://pbs.twimg.com/profile_images/610120554738266112/I4pl2ygE_400x400.jpg")
                              )
                          )
                      ),
                      new Text('Lars Løkke',
                        style: new TextStyle(
                          fontSize: 20.0,
                        ),
                      ),
                      new Text('Venstre',
                        style: new TextStyle(
                          fontSize: 15,
                        ),
                      ),
                    ],
                  ),

在图片中可以看到完整的布局,并用蓝色勾勒出我想要有图像背景的位置:

Layout image

希望你能帮助我,谢谢。

dart flutter flutter-layout
1个回答
0
投票

简单包裹 - Column与 - DecoratedBox

码:

FlipCard(
               direction: FlipDirection.HORIZONTAL, // default
              child: Container(
                  decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.black),
                    borderRadius: BorderRadius.circular(10.0),
                  ),
                  margin: EdgeInsets.all(10.0),
                  child: new Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        DecoratedBox(  // add this
                          child: new Column(
                            children: <Widget>[
                              new Container(
                                  margin: EdgeInsets.all(10),
                                  width: 190.0,
                                  height: 190.0,
                                  decoration: new BoxDecoration(
                                      shape: BoxShape.circle,
                                      border: new Border.all(color: Colors.black),
                                      image: new DecorationImage(
                                          fit: BoxFit.fill,
                                          image: new NetworkImage(
                                              "https://pbs.twimg.com/profile_images/610120554738266112/I4pl2ygE_400x400.jpg")))),
                              new Text(
                                'Lars Løkke',
                                style: new TextStyle(
                                  fontSize: 20.0,
                                  color: Colors.white
                                ),
                              ),
                              new Text(
                                'Venstre',
                                style: new TextStyle(
                                  fontSize: 15,
                                    color: Colors.white
                                ),
                              ),
                            ],
                            mainAxisSize: MainAxisSize.min,
                          ),
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: NetworkImage(
                                      'https://placeimg.com/640/480/any'),fit: BoxFit.fill)),
                        ),
                      ]))),

输出:

enter image description here

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