I am new to flutter. and I am trying to make an x o game. I am still on the very first steps of the app. I am using gridview.count to make the layout of the game. The problem is the properties of the stateful widget(choice, onTap()) is not defined in the gridview tile. This is my code
return Scaffold(
appBar: AppBar(title: Text('Tic Tac Toe')),
body: GridView.count(
crossAxisCount: 3,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
children: List<Widget>.generate(
9,
(int index) {return new GridTile(
child:GridCell(
choice: _choice,
onTap: ()=>onTap(context),
),
);
})))
and the class is:
class GridCellState extends State<TicTacToe> {
final String choice;
final VoidCallback onTap;
GridCellState({Key key, this.choice, this.onTap}) :
super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap:onTap,
child:Container(
child: Text(choice),
height:20.0,
color:Theme.of(context).primaryColor,
),
);
}
}
Thanks in advance.