给定的垂直视口高度未被限定

334

这是我的代码:

@override
Widget build(BuildContext context) {
  return new Material(
    color: Colors.deepPurpleAccent,
    child: new Column(
     mainAxisAlignment: MainAxisAlignment.center,
        children:<Widget>[new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
          return new Center(
              child: new CellWidget()
          );
        }),)]
    )
  );
}

以下是异常信息:

I/flutter ( 9925): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 9925): The following assertion was thrown during performResize():
I/flutter ( 9925): Vertical viewport was given unbounded height.
I/flutter ( 9925): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 9925): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 9925): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 9925): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 9925): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 9925): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 9925): the height of the viewport to the sum of the heights of its children.
I/flutter ( 9925): 
I/flutter ( 9925): When the exception was thrown, this was the stack:
I/flutter ( 9925): #0      RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:827:15)
I/flutter ( 9925): #1      RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:880:6)
I/flutter ( 9925): #2      RenderObject.layout (package:flutter/src/rendering/object.dart:1555:9)

您也可以使用简单的容器,而不是Column(主要用于多个子小部件)。 - Napolean
1
小部件构建(BuildContext context) { 返回新的材料( 颜色:Colors.deepPurpleAccent, 孩子:新容器( 对齐方式: 对齐.中心, 孩子: 新网格视图计数(crossAxisCount:_column,children:新列表生成(_row*_column, (索引) { 返回新中心( 孩子: 新单元小部件() ); }) ), ) ); --此代码也不能帮助@Napolean - pallav bohara
尝试在Column下添加mainAxisSize到max,并查看是否有所帮助。 - pblead26
27个回答

0

0
在我的情况下,我不得不将ListView包装在一个Container中,并给这个容器一个特定的高度。

0
如果您在 SingleChildScrollView 中有一个 ListView,请在 ListView 中设置 shrinkWrap:True 和 physics: const NeverScrollableScrollPhysics()。

目前你的回答表述不清楚。请进行[编辑]以添加更多细节,帮助其他人理解如何回答该问题。你可以在帮助中心找到关于撰写好的答案的更多信息。 - Community

0

也遇到了这个错误,因为代码像这样

return Container(
      child: Column(
        children: [
          ListView.separated(
              itemBuilder: (context, index) {
                return CircleManagerSettingItem(widget.membersInfo[index]);
              },
              separatorBuilder: (_, index) => DD(
                    height: 1,
                    paddingLeft: 10,
                    paddingRight: 10,
                  ),
              itemCount: (widget.membersInfo.length)),
        ],
      ),
    );

移除 Container 中的 Column,然后确定即可。


0
你也可以将Expanded()作为该小部件的父级。

0

这对我有用,并保持了ListView的可滚动性

return ListView(
shrinkWrap: true, //<-
physics: ClampingScrollPhysics(), //<-
children: <Widget>[
        ListTile(
            title: Text("Exp1")),
 ListTile(
            title: Text("Exp2"))]);

-1

如果你正在使用 CustomScrollView

可以尝试使用 SliverFillRemaining


虽然这段代码可能回答了问题,但提供有关它如何以及/或为什么解决问题的附加上下文将改善答案的长期价值。您可以在帮助中心找到有关如何编写良好答案的更多信息:https://stackoverflow.com/help/how-to-answer。祝你好运。 - nima

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接