From ddcd679fe9ddd8f69abab740c2feda45d29249b5 Mon Sep 17 00:00:00 2001 From: Jochum van der Ploeg Date: Wed, 20 Jan 2021 22:11:33 +0100 Subject: [PATCH] Added a `required` to GameWidget and updated the docs (#638) * Added a required to GameWidget and updated the docs * Removed entry from CHANGELOG --- CHANGELOG.md | 1 + doc/game.md | 5 ++++- lib/src/game/game_widget.dart | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c913da97e..2659c549541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Added `Composition`, allows for composing multiple images into a single image. - Move files to comply with the dart package layout convention - Fix gesture detection bug of children of `PositionComponent` + - The `game` argument on `GameWidget` is now required ## 1.0.0-rc5 - Option for overlays to be already visible on the GameWidget diff --git a/doc/game.md b/doc/game.md index 98b8a57f5c6..a1d944e0dfe 100644 --- a/doc/game.md +++ b/doc/game.md @@ -27,14 +27,17 @@ class MyGameSubClass extends Game { main() { + final myGame = MyGameSubClass(); runApp( GameWidget( - game: MyGameSubClass(), + game: myGame, ) ); } ``` +**Note:** Do not instantiate your game in a build method. Instead create an instance of your game and reference it within your widget structure. Otherwise your game will be rebuild every time the Flutter tree gets rebuild. + It is important to notice that `Game` is an abstract class with just the very basic implementations of the gameloop. As an option and more suitable for most cases, there is the full-featured `BaseGame` class. For example, Forge2D games uses `Forge2DGame` class; diff --git a/lib/src/game/game_widget.dart b/lib/src/game/game_widget.dart index 6e157e8f578..f03585ae2a0 100644 --- a/lib/src/game/game_widget.dart +++ b/lib/src/game/game_widget.dart @@ -99,7 +99,7 @@ class GameWidget extends StatefulWidget { /// ``` const GameWidget({ Key key, - this.game, + @required this.game, this.textDirection, this.loadingBuilder, this.errorBuilder,