gpt4 book ai didi

flutter - 如何在 Flutter 中的行小部件内的容器上添加边框?

转载 作者:行者123 更新时间:2023-12-03 21:58:35 26 4
gpt4 key购买 nike

        Container(
// decoration: BoxDecoration(
// border: Border.all(color: Colors.black45),
// borderRadius: BorderRadius.circular(8.0),
// ),
child: Row(
children: <Widget>[
Container(
child: Text("hi"),
margin : EdgeInsets.fromLTRB(20, 8, 8, 16),
width: MediaQuery.of(context).size.width *0.42,
height: 90,
color: Colors.black12,
),

Container(
child: Text("Hi"),
margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42 ,
height: 90,
color: Colors.black12,
)
],
),
),

我可以在外部容器上使用 Box 装饰添加边框,但是当我尝试在内部容器上执行相同操作时,它会引发错误。问题是什么以及如何解决?

最佳答案

为了在行小部件内的容器上添加边框,我们必须对内部容器使用装饰。
一旦您发布错误,我们可以更好地回答您,但我认为以下代码将对您有所帮助。
如果你使用的是装饰,那么你不能直接在容器中添加颜色属性,它应该只是在装饰中。

     Container(
child: Row(
children: <Widget>[
Container(
child: Text("hi"),
margin: EdgeInsets.fromLTRB(20, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42,
height: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
border: Border.all(
color: Colors.blue,
width: 4,
)),
),
Container(
child: Text("Hi"),
margin: EdgeInsets.fromLTRB(16, 8, 8, 16),
width: MediaQuery.of(context).size.width * 0.42,
height: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
shape: BoxShape.rectangle,
border: Border.all(
color: Colors.blue,
width: 4,
)),
)
],
),
),

关于flutter - 如何在 Flutter 中的行小部件内的容器上添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60830260/

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