flutter - 当我的 ListView 在展开时出现 RenderBox 错误
问题描述
我遵循了其他解决方案,其中用户将 ListView 放入展开后,然后将展开后放入 SizedBox,然后将 SizedBox 放入一行。我仍然收到渲染框错误。
在 null 上调用了方法“>”。接收者:null 尝试调用:
(1e-10) 相关的导致错误的小部件是:Row
代码是:
return new Row(children: [
new Expanded(
child: SizedBox(
width: double.infinity,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: getPostItems(snapshot),
))
)]);
我想要身高
解决方案
double.infinity
用于使元素的长度与父元素的长度相同。在示例中,SizedBox
试图与 的宽度相同Row
,后者是根据子级扩展的 Widget,其宽度无限。试试这个:
Expanded(
child: Container( // This way, the Container should fit into a non infinite width or height, but rather the dimensions of the remaining space of another widget
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: getPostItems(snapshot),
)
)
)
推荐阅读
- azure - Azure DevOps Pipelines 中的条件阶段执行
- c - 在 C 中调整二维数组的大小。内存泄漏
- javascript - 通过匹配相似列上的元素加入两个多维数组javascript es6
- javascript - react-vis径向饼图的padAngle属性不起作用
- javascript - 使用 javascript 查找没有正确类名或 id 的 html 元素
- git - git pull --porcelain like 选项
- regex - Ruby - 如何返回匹配的正则表达式值
- django - Django查询在另一个字段上应用不同的注释
- c# - 在 .net 4x 和 .net 5 应用程序之间共享身份验证 Cookie - 访问用户声明原则
- laravel - 如何为行添加编号列