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

Flutter Row组件文本溢出问题解决咨询

Flutter文本溢出问题解决方案

你的问题出在右侧Row中的Text组件未被限制宽度,导致文本过长时无法自动换行或截断,从而触发溢出错误。以下是几种可行的解决方式:


方法1:用Expanded包裹Text组件

给文本外层套Expanded,让它占据Row内的剩余空间,自动换行显示:

Expanded(
  child: Row(  
    children: [
      Image.asset(
        "assets/location_pin.png",
        height: 18,
        width: 18,
        color: MyColor.primaryRedColor,
      ),
      // 给Text添加Expanded包裹
      Expanded(
        child: Text(
          "WTC Tower, Los Angeless sbdjkds jsbksdb kcbk",
          style: textStyleWith12600(MyColor.blackColor),
        ),
      ),
    ],
  ),
)

方法2:用Flexible替代Expanded

如果不需要强制占满剩余空间,可使用Flexible,效果类似但更灵活:

Expanded(
  child: Row(  
    children: [
      Image.asset(
        "assets/location_pin.png",
        height: 18,
        width: 18,
        color: MyColor.primaryRedColor,
      ),
      Flexible(
        child: Text(
          "WTC Tower, Los Angeless sbdjkds jsbksdb kcbk",
          style: textStyleWith12600(MyColor.blackColor),
        ),
      ),
    ],
  ),
)

方法3:设置Text的溢出截断

如果不想换行,希望超出部分显示省略号,可直接给Text添加overflow和maxLines属性:

Text(
  "WTC Tower, Los Angeless sbdjkds jsbksdb kcbk",
  style: textStyleWith12600(MyColor.blackColor),
  overflow: TextOverflow.ellipsis,
  maxLines: 1, // 限制只显示一行
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 21:46:05