ListenerGameWidget<T extends Game> constructor

ListenerGameWidget<T extends Game>({
  1. Key? key,
  2. required T game,
  3. TextDirection? textDirection,
  4. GameLoadingWidgetBuilder? loadingBuilder,
  5. GameErrorWidgetBuilder? errorBuilder,
  6. WidgetBuilder? backgroundBuilder,
  7. Map<String, OverlayWidgetBuilder<T>>? overlayBuilderMap,
  8. List<String>? initialActiveOverlays,
  9. FocusNode? focusNode,
  10. bool autofocus = true,
  11. MouseCursor? mouseCursor,
  12. bool addRepaintBoundary = true,
})

Renders a game in a flutter widget tree.

Ex:

// Inside a State...
late MyGameClass game;

@override
void initState() {
  super.initState();
  game = MyGameClass();
}
...
Widget build(BuildContext  context) {
  return GameWidget(
    game: game,
  )
}
...

It is also possible to render layers of widgets over the game surface with widget subtrees.

To do that a overlayBuilderMap should be provided. The visibility of these overlays are controlled by Game.overlays property

Ex:

...

final game = MyGame();

Widget build(BuildContext  context) {
  return GameWidget(
    game: game,
    overlayBuilderMap: {
      'PauseMenu': (ctx, game) {
        return Text('A pause menu');
      },
    },
  )
}
...
game.overlays.add('PauseMenu');

Implementation

ListenerGameWidget({
  Key? key,
  required T this.game,
  this.textDirection,
  this.loadingBuilder,
  this.errorBuilder,
  this.backgroundBuilder,
  this.overlayBuilderMap,
  this.initialActiveOverlays,
  this.focusNode,
  this.autofocus = true,
  this.mouseCursor,
  this.addRepaintBoundary = true,
})  : gameFactory = null,
      super(key: key) {
  _initializeGame(game!);
}