刚接触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/