(RenderViewport不支持返回内在尺寸
我正面临着这个 例外 :
FlutterError(RenderViewport 不支持返回内在 方面。计算内在尺寸需要 实例化视口的每个子项,这违背了 视口很懒。如果您只是想收缩包装 视口在主轴方向,考虑 RenderShrinkWrappingViewport 渲染对象(ShrinkWrappingViewport widget),它在不实现内在的情况下实现了这种效果 维度 API。)
当我添加 ProductsWidget
时,会发生异常。
Products Widget的代码是:
class ProductsWidget extends GetResponsiveView<HomeTabController> {
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: 3,
// padding: EdgeInsets.symmetric(vertical: 20),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Column(
children: [
Row()])}}
调用代码是:
body: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
// flex: 1,
child: HomeAppBar()),
// listView
// i made shrinkWrap=true
// neverScroll
Flexible(fit: FlexFit.tight, child: ProductsWidget()),
],
),
),
),
);
}),
I am facing this
Exception :
FlutterError (RenderViewport does not support returning intrinsic
dimensions. Calculating the intrinsic dimensions would require
instantiating every child of the viewport, which defeats the point of
viewports being lazy. If you are merely trying to shrink-wrap the
viewport in the main axis direction, consider a
RenderShrinkWrappingViewport render object (ShrinkWrappingViewport
widget), which achieves that effect without implementing the intrinsic
dimension API.)
When i add ProductsWidget
the Exception occurs.
the code of Products Widget is:
class ProductsWidget extends GetResponsiveView<HomeTabController> {
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: 3,
// padding: EdgeInsets.symmetric(vertical: 20),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Column(
children: [
Row()])}}
the calling code is:
body: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
// flex: 1,
child: HomeAppBar()),
// listView
// i made shrinkWrap=true
// neverScroll
Flexible(fit: FlexFit.tight, child: ProductsWidget()),
],
),
),
),
);
}),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试将 ProductsWidget 包装在 SizedBox 中,并为其指定宽度(宽度:double.maxFinite)和可能的高度。
我遇到了类似的问题,我发现以下帖子很有帮助: flutter listview with收音机未显示在警报对话框中
Try wrapping your ProductsWidget in a SizedBox and give it a width (width: double.maxFinite,) and potentially height.
I had a similar issue and I found the following post helpful: flutter listview with radio not showing in alertDialog
这是因为 ListView 延迟构建每个子项。您可以使用包含在 SingleChildScrollView 中的 Column 而不是 ListView。
That is because ListView builds each child lazily. You can use a Column wrapped in a SingleChildScrollView instead of the ListView.
将
SingleChildScrollView
替换为CustomScrollView
,如下所示:Replace
SingleChildScrollView
withCustomScrollView
like this:我通过用 SizedBox 包装并给出潜在的高度和宽度解决了我的问题。然后我用Column包裹了SizedBox。
I solved my problem by wrapping with SizedBox and give potential height and width. Then I wrapped the SizedBox with Column.
出现此问题的原因是在 Renderviewport 中使用 Listview。要解决这个问题,您可以将 Listview 包装在 SizedBox 中,并为其指定 double.maxFinite 的高度和宽度(或任何需要的值)
我的代码:
The issue happens because of using the Listview inside the Renderviewport. To solve it you can wrap your Listview in a SizedBox and give it a height and width of double.maxFinite (or whatever is needed)
My code:
将 ListView 转换为 List.generate 即可解决问题。
Convert ListView to List.generate and it will solve the problem.