dart - 展开的小部件必须放在 Flex 小部件内

刚接触flutter,有人能告诉我下面的代码有什么问题吗

  class GamePage extends StatelessWidget {
  int _row;
  int _column;

  GamePage(this._row,this._column);

  @override
  Widget build(BuildContext context) {
    return new Material(
      color: Colors.deepPurpleAccent,
      child:new Expanded(
          child:new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
        return new Center(
            child: new CellWidget()
        );
      }),) )


    );
  }
}

附加错误截图。

最佳答案

您没有 Flex 祖先。

An Expanded widget must be a descendant of a Row, Column, or Flex, and the path from the Expanded widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).

我不确定您是否需要 Expanded。但是将其删除或将其包装在 Column 中应该可以解决问题。

https://stackoverflow.com/questions/50250789/

相关文章:

flutter - 如何降级 Flutter SDK (Dart 1.x)

dart - 在 Flutter 中创建图像轮播

dart - 在底部导航栏图标上显示通知徽章

dart - 如何在 Flutter 中更改状态栏颜色?

dart - flutter - 创建一个从 minHeight 开始,增长到 maxHeight

image - Flutter 网络图像不适合圆形头像

flutter - 如何让 Flutter 应用根据不同的屏幕尺寸做出响应?

constructor - Dart 构造函数后的冒号

flutter - 如何检查 Flutter 应用程序是否正在调试中运行?

intellij-idea - 如何将数据记录到 Flutter 控制台?