flutter - 垂直视口(viewport)被赋予了无限的高度

这是我的代码:

@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)

最佳答案

添加这两行

ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
...

https://stackoverflow.com/questions/50252569/

相关文章:

android - 使用 Flutter 的 Android Studio 中不显示设备列表

flutter - 如何在 Flutter 中创建 GridView 布局

dart - 如何检测 Flutter 中布局的方向变化?

flutter - 如何在 ListView 中添加滚动指示器

dart - 如何为 qa/dev/prod 构建不同版本的 Flutter 应用程序?

dart - 如何将数据从子小部件传递到其父小部件

flutter - 如何从 Flutter 应用程序调用电话

google-maps - 如何在 Flutter 中更改谷歌地图标记的图标大小?

dart - 带有快速拨号的 flutter float Action 按钮

flutter - 在 iphone 上安装使用 android studio 开发的 Flutte