用例:在同一个Row
上放置两个按钮,但它们可以适应多种屏幕尺寸(自适应)
问题::我有两个按钮(每个按钮都包装在column
小部件中),它们包装在Row
小部件中。
总和:(父级->子级):行> [列-列]
如下面的屏幕截图所示。
尝试的解决方案::我尝试将窗口小部件放置在扩展窗口小部件内,该窗口小部件放置在Flex窗口小部件内
填充> Flex>展开>行> [小部件]
代码如下:
Padding( //Main Padding
padding: EdgeInsets.only(top: 14, bottom: 14),
child: Flex(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
direction: Axis.horizontal,
children: <Widget>[
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
ChipButton(text: 'Main Size', withIcon: false),
ChipButton(text: 'Others', withIcon: false),
],
),
),
],
),
),
Padding(
padding: EdgeInsets.only(top: 14, bottom: 14),
child: Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
ChipButton(text: 'trademark', withIcon: false),
],
),
),
),
Padding(
padding: EdgeInsets.only(top: 14, bottom: 14),
child: Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
ChipButton(text: 'Price', withIcon: false),
ChipButton(text: 'Color', withIcon: false),
],
),
),
),
答案 0 :(得分:3)
尝试将以下代码修改为您的应用:
Padding(
padding: EdgeInsets.only(top: 14, bottom: 14),
child: Column(children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child:
Container(color: Colors.amberAccent, child: Text("A"))),
Expanded(
child:
Container(color: Colors.blueAccent, child: Text("B"))),
]),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(color: Colors.grey, child: Text("C")),
),
]),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child:
Container(color: Colors.redAccent, child: Text("D"))),
Expanded(
child: Container(
color: Colors.orangeAccent, child: Text("E"))),
]),
]),
),
它会产生如下内容:
您还可以查看我在here上工作过的DartPad代码,以防您想检查它是否在不同的宽度上工作:D
P.S。我真的很喜欢你问问题的方式。