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

Flutter信息流页面导航失败,触发constraints.hasBoundedWidth断言错误

问题分析与解决方案

错误'constraints.hasBoundedWidth': is not true的核心原因是ListView被包裹在FittedBox中——FittedBox会向子组件传递无边界的宽度约束,而ListView需要明确的、有界的宽度才能完成布局渲染。

修复步骤

直接移除外层的FittedBox即可解决问题,修改后的代码片段如下:

body: [
  ListView.builder(
    padding: const EdgeInsets.only(top: 0),
    physics: const NeverScrollableScrollPhysics(),
    shrinkWrap: true,
    itemBuilder: (context, index) {
      return index >= postState.posts.length
          ? const IndicatorWidget()
          : PostListItem(
              post: postState.posts[index],
            );
    },
    itemCount: postState.hasReachedMax
        ? postState.posts.length
        : postState.posts.length + 1,
    controller: _scrollController,
  )
],

额外说明

  • 移除FittedBox后,ListView会自动继承DraggableHome提供的父组件宽度约束,满足constraints.hasBoundedWidth的断言要求。
  • 你原代码中设置的shrinkWrap: true和NeverScrollableScrollPhysics是合理的,因为DraggableHome自身已经处理了页面的滚动逻辑,子ListView不需要独立滚动。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 09:15:15