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

Flutter:NodeExpansionTile组件文本在华为Mate30上垂直截断

解决华为Mate30上NodeExpansionTile文本垂直截断问题的思路

针对仅在华为Mate30设备上出现的NodeExpansionTile文本垂直轻微截断问题,可尝试以下几个方向排查和解决:

  • 调整Text组件的行高与内边距
    不同设备的字体渲染逻辑存在差异,Mate30的系统字体可能导致subtitle1样式的默认行高不足以容纳文本高度。可以给Text组件添加垂直内边距,或显式设置行高:

    title: Padding(
      padding: const EdgeInsets.symmetric(vertical: 2.0),
      child: Text(
        (company.code ?? I10n.of(context).noDataText)+' '+(company.name ?? I10n.of(context).noDataText),
        style: company.isSelected
            ? themeData.textTheme.subtitle1!.copyWith(
                color: themeData.primaryColor,
                fontWeight: FontWeight.w400,
                height: 1.2, // 按需调整行高
              )
            : themeData.textTheme.subtitle1!.copyWith(
                fontWeight: FontWeight.w400,
                height: 1.2,
              ),
      ),
    ),
    
  • 给Title区域添加最小高度约束
    自定义NodeExpansionTile的title区域可能在Mate30的屏幕密度下垂直空间不足。可以用SizedBox包裹Text,指定最小高度并确保文本垂直居中:

    title: SizedBox(
      height: 26, // 根据实际显示效果调整
      child: Align(
        alignment: Alignment.centerLeft,
        child: Text(
          // 原文本内容与样式
        ),
      ),
    ),
    
  • 优化字体渲染参数
    Mate30的系统字体可能存在行高分布不均的情况,可通过leadingDistribution参数(Flutter 3.7及以上版本支持)优化行高分布:

    style: company.isSelected
        ? themeData.textTheme.subtitle1!.copyWith(
            color: themeData.primaryColor,
            fontWeight: FontWeight.w400,
            leadingDistribution: TextLeadingDistribution.even,
          )
        : themeData.textTheme.subtitle1!.copyWith(
            fontWeight: FontWeight.w400,
            leadingDistribution: TextLeadingDistribution.even,
          ),
    
  • 检查NodeExpansionTile内部布局约束
    如果NodeExpansionTile是自定义组件,需排查其内部是否存在硬编码的垂直尺寸或内边距,这些值在Mate30的屏幕密度下可能导致文本被挤压。尝试将固定尺寸替换为弹性约束,或根据设备动态调整内边距。

内容的提问来源于stack exchange,提问作者Joy Zhu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 07:02:25