Skip to content

Instantly share code, notes, and snippets.

@Dev-Owl
Created October 13, 2019 15:29
Show Gist options
  • Save Dev-Owl/8c67ec2d3d86f14810125f594b5a01de to your computer and use it in GitHub Desktop.
Save Dev-Owl/8c67ec2d3d86f14810125f594b5a01de to your computer and use it in GitHub Desktop.
Main widget part 2
@override
Widget build(BuildContext contGameOfLifeext) {
final screenSize = MediaQuery.of(context).size;
_cellSize = Size(
screenSize.width / GameOfLife.rowLength,
(screenSize.height - kToolbarHeight) /
(GameOfLife.worldSize / GameOfLife.rowLength));
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: <Widget>[
FlatButton(
child: Icon(Icons.restore),
onPressed:() {
if(_game.running)
_game.toggleGame();
setState(() {
_game.resetWorld();
});
} ,
)
],
),
body: StreamBuilder<double>(
stream: _game.stateController.stream,
builder: (context, snapshot) {
return GameBoard(
GameOfLife.cellMargin,
_game.world,
GameOfLife.rowLength,
cellSize: _cellSize,
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: _toggleGame,
tooltip: 'Start/Stop',
child: _game.running ? Icon(Icons.pause) : Icon(Icons.play_arrow),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment