GameWidget<T extends Game>.controlled constructor

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

A GameWidget which will create and own a Game instance, using the provided gameFactory.

This constructor can be useful when you want to put GameWidget into another widget, but would like to avoid the need to store the game's instance yourself. For example:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(20),
      child: GameWidget.controlled(
        gameFactory: MyGame.new,
      ),
    );
  }
}

Implementation

const GameWidget.controlled({
  required GameFactory<T> this.gameFactory,
  this.textDirection,
  this.loadingBuilder,
  this.errorBuilder,
  this.backgroundBuilder,
  this.overlayBuilderMap,
  this.initialActiveOverlays,
  this.focusNode,
  this.autofocus = true,
  this.mouseCursor,
  this.addRepaintBoundary = true,
  super.key,
}) : game = null;