gpt4 book ai didi

flutter - 我想在 Flutter 中将我的行分成 1/4 的比例

转载 作者:行者123 更新时间:2023-12-04 11:06:37 25 4
gpt4 key购买 nike

我想将 flutter 中的行分成 4 列,宽度相同。到目前为止,我想出的解决方案是这样的,

   child: Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.greenAccent),
),
Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.yellow),
),
Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.blue),
),
Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.white),
),
],
),

有没有什么替代方法。在这种方法中,将行分成 1/3 的比例也不起作用。

最佳答案

您可以通过使用 Expanded Widget 来实现这一点。

检查下面的代码:

它工作得很好。

1) For 1/3 ratio


Row(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.greenAccent),
),
),
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.yellow),
),
),
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.blue),
),
),
],
),

1) For 1/4 ratio


Row(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.greenAccent),
),
),
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.yellow),
),
),
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.blue),
),
),
Expanded(
flex: 1,
child: Container(
width: MediaQuery.of(context).size.width * 0.25,
decoration: BoxDecoration(color: Colors.white),
),
),
],
),

请参阅下面的输出:

enter image description here

enter image description here

我希望这回答了你的问题。

关于flutter - 我想在 Flutter 中将我的行分成 1/4 的比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61616336/

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