【问题标题】:ListTile: Extending subtitle bounds below trailing areaListTile:在尾随区域下方扩展字幕边界
【发布时间】:2021-09-13 08:37:12
【问题描述】:

上面的视图是这段代码的结果:

    ListTile(
      leading: Container(color: Colors.blue, child: Text("leading")),
      title: Container(color: Colors.green, child: Text("title")),
      subtitle: Container(color: Colors.red, child: Text("subtitle")),
      trailing: Container(color: Colors.yellow, child: Text("trailing")),
    )

我正在尝试扩展红色“字幕”的区域,使其一直延伸到“triling”结束,但我不想使用像完全删除“trailing”和使用一行这样的肮脏技巧。

更新

这是我需要的:

【问题讨论】:

  • 你想你的字幕是尾随的结尾吗?
  • ListTile 是不可能的

标签: flutter flutter-listview


【解决方案1】:

填充应该可以很好地设置边界,这样

ListTile(
      leading: Container(color: Colors.blue, child: Text("leading")),
      title: Container(color: Colors.green, child: Text("title")),
      subtitle: Padding(
                    //upper bound
                    padding: const EdgeInsets.only(top: 10),
                    child:Container(color: Colors.red, child: Text("subtitle")),
                        ),
      trailing: Container(color: Colors.yellow, child: Text("trailing")),
    )

【讨论】:

    【解决方案2】:

    参考文档:

    要显示右对齐的元数据,请考虑使用 [Row] 与 [CrossAxisAlignment.baseline] 对齐,其第一项是 [扩展] 并且其第二个孩子是元数据文本,而不是 使用[尾随]

    我避免使用尾随。按照 cmets 中给出的建议解决了这个问题。

    ListTile(title: Row(children: [ Expanded(main), Text('trailing') ]));
    

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 2019-10-14
      • 2016-10-11
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 2017-09-16
      相关资源
      最近更新 更多