gpt4 book ai didi

flutter - 具有不等权重元素的行

转载 作者:行者123 更新时间:2023-12-02 03:05:04 24 4
gpt4 key购买 nike

我有一行横跨屏幕的宽度,并且包含三个按钮和一个等距的文本(flex = 1)。我希望文本与屏幕中心对齐,按钮与两端对齐。这可能吗?

enter image description here

最佳答案

To cause a child to expand to fill the available space in the direction of this widget's main axis, wrap the child in an Expanded widget.

所以你可以尝试Expanded并声明Flex在第二个扩展小部件中。

解决方案

          Row(
children: <Widget>[
Expanded(child: Container(padding: EdgeInsets.all(16),color: Colors.red,child: Text("text 1"))),
Expanded(flex: 3,child: Container(padding: EdgeInsets.all(16),color: Colors.blue,child: Text("text 2"))),
Expanded(child: Container(padding: EdgeInsets.all(16),color: Colors.yellow,child: Text("text 3"))),
Expanded(child: Container(padding: EdgeInsets.all(16),color: Colors.green,child: Text("text 4"))),
],
),

输出:

enter image description here

关于flutter - 具有不等权重元素的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59216716/

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