gpt4 book ai didi

dart - 如何将图像背景分配给 flutter 中的列

转载 作者:行者123 更新时间:2023-12-03 03:41:25 25 4
gpt4 key购买 nike

我想知道如何在 flutter 中将图像添加到我的事件卡片中的列中作为背景。

关于我想在何处添加图像的代码如下所示(从子新列到末尾):

 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

希望你能帮助我,谢谢。

最佳答案

DecoratedBox 简单地包装 - Column

代码:

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

关于dart - 如何将图像背景分配给 flutter 中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55147293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com