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

Flutter AlertDialog触发RenderBox未布局报错排查

问题根因

这个报错和外层ListView、VxBox卡片布局没有关系,问题就出在AlertDialog本身的配置上:
你给AlertDialog开了scrollable: true,但是没有传content参数。你当前使用的Flutter版本中,开启滚动模式的AlertDialog内部会用可滚动容器统一包裹标题和内容区,内容区为空的时候,可滚动组件无法计算自身尺寸,直接触发渲染层的hasSize断言失败,你看到的那一堆RenderCustomPaint、RenderPhysicalShape、RenderShiftedBox报错全是这个问题连锁触发的。

修复方法

根据实际需求任选一种即可:

  • 要是弹窗只显示短标题,根本不需要滚动,直接把scrollable: true那行删掉就行,这是最省事的改法。改完的代码参考:
IconButton(
  onPressed: () {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: "title".text.make(),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(context),
                child: const Text("关闭"),
              )
            ],
          );
        });
  },
  icon: Icon(
    Iconsax.award5,
    color: AutiTheme.white,
    semanticLabel: "Autisure Assured", 
  ),
)
  • 要是后续要放长文本确实需要滚动,那就别让content空着,哪怕暂时没内容先传个SizedBox.shrink()占位,后续再补实际内容就行,示例:
IconButton(
  onPressed: () {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            scrollable: true,
            title: "title".text.make(),
            content: const Text("这里放弹窗正文,长内容会自动滚动"),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(context),
                child: const Text("关闭"),
              )
            ],
          );
        });
  },
  icon: Icon(
    Iconsax.award5,
    color: AutiTheme.white,
    semanticLabel: "Autisure Assured", 
  ),
)

如果改完还报错,就检查下你用的VelocityX版本,部分低版本的VxText在弹窗的无界约束下会出布局问题,把"title".text.make()换成Flutter原生的Text("title")试下即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.29 18:15:58