flutter:列对齐项具有相同的宽度
问题内容:
我正在尝试将列内的小部件与CrossAxisAlignment.center对齐在中心,但我也希望这些小部件具有相同的宽度。我该如何实现?
问题答案:
您可以通过将设置CrossAxisAlignment
为Stretch,然后将包裹起来,得到与之类似Column
的内容IntrinsicWidth
;如果您想给它们指定特定的宽度,请使用stepWidth
属性
Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RaisedButton(
child: Text("hello"),
onPressed: () {},
),
RaisedButton(
child: Text("another hello"),
onPressed: () {},
),
RaisedButton(
child: Text("DB"),
onPressed: () {},
),
],
),
),
),