You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中ExpansionTile组件下文本重叠问题求助

Flutter ExpansionTile内Text组件文本重叠问题解决

在ExpansionTile的内容区域用Column嵌套多个Text组件时,前两个文本出现了重叠粘连的情况,其余Text显示正常。使用的是bodyLarge文本主题搭配谷歌字体Nunito,相关代码如下:

Column(
  children:[
    Text('     a  temperature higher than 37.5°C or more ',
      style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
    Text('     yellow  discharge or crustiness around the eyes  ',
      style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
    Text('     inflamed  puffy eyes, or red eyes (pink eye)  ',
      style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
  ]),

可以试试这几种解决办法:

  • 给Text组件添加上下间距:直接在每个Text外层套Padding,强制拉开文本间的距离:

    Column(
      children:[
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 4.0),
          child: Text('     a  temperature higher than 37.5°C or more ',
            style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 4.0),
          child: Text('     yellow  discharge or crustiness around the eyes  ',
            style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 4.0),
          child: Text('     inflamed  puffy eyes, or red eyes (pink eye)  ',
            style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
        ),
      ]),
    
  • 用ListView替代Column:ExpansionTile的内容区域布局约束可能导致Column的子组件间距计算异常,换成ListView(设置shrinkWrap: true)可以自动处理子组件的垂直间距:

    ListView(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      children:[
        Text('     a  temperature higher than 37.5°C or more ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
        Text('     yellow  discharge or crustiness around the eyes  ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
        Text('     inflamed  puffy eyes, or red eyes (pink eye)  ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey)),
      ]),
    
  • 统一文本行高:字体基线对齐问题也可能导致重叠,通过设置Text的strutStyle属性固定行高:

    Column(
      children:[
        Text('     a  temperature higher than 37.5°C or more ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey),
          strutStyle: const StrutStyle(height: 1.5)),
        Text('     yellow  discharge or crustiness around the eyes  ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey),
          strutStyle: const StrutStyle(height: 1.5)),
        Text('     inflamed  puffy eyes, or red eyes (pink eye)  ',
          style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey),
          strutStyle: const StrutStyle(height: 1.5)),
      ]),
    

内容的提问来源于stack exchange,提问作者凯文Beno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 15:51:54