我有一列,它的所有子项都是单词行(文本小部件),每行都有 MainAxisAlignment.spaceBetween 的主要对齐方式。我想将列的宽度设置为子项之间最长的行,其他行将相应地更改之间的间距。
我的代码:
Container(
color: Colors.green,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('A', style: Theme.of(context).textTheme.headline4),
Text('B', style: Theme.of(context).textTheme.headline4),
Text('C', style: Theme.of(context).textTheme.headline4)
]),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('A', style: Theme.of(context).textTheme.headline4),
Text('B', style: Theme.of(context).textTheme.headline4),
Text('C', style: Theme.of(context).textTheme.headline4),
Text('D', style: Theme.of(context).textTheme.headline4),
Text('E', style: Theme.of(context).textTheme.headline4),
]),
]))
假设我无法在容器中将其设置为固定宽度,如何将列宽(动态)设置为最长的行?
最佳答案
将您的Column
包裹在IntrinsicWidth
中:
IntrinsicWidth(
child: Column(
children: [
Row(...),
Row(...),
],
),
)
关于flutter - 如何将列宽设置为其子行中最长的列宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66872488/