【问题标题】:How to set Column width to the longest of its children say Row?如何将列宽设置为其子项中最长的行?
【发布时间】:2021-06-26 13:28:17
【问题描述】:

我有一个列,它的所有子项都是单词行(文本小部件),每行都有 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),
      ]),
  ]))

预期结果:

实际结果:

假设我不能在容器中将列宽设置为固定宽度,我该如何(动态地)将其设置为最长行?

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    将您的Column 包裹在IntrinsicWidth 中:

    IntrinsicWidth(
      child: Column(
        children: [
          Row(...),
          Row(...),
        ],
      ),
    )
    

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2020-09-14
      • 1970-01-01
      相关资源
      最近更新 更多