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
相关产品推荐
相关产品推荐

