GameWidget<T extends Game> class

The GameWidget is a Flutter widget which is used to insert a Game instance into the Flutter widget tree.

The GameWidget is sufficiently feature-rich to run as the root of your Flutter application. Thus, the simplest way to use GameWidget is like this:

void main() {
  runApp(
    GameWidget(game: MyGame()),
  );
}

At the same time, GameWidget is a regular Flutter widget, and can be inserted arbitrarily deep into the widget tree, including the possibility of having multiple GameWidgets within a single app.

The layout behavior of this widget is that it will expand to fill all available space. Thus, when used as a root widget it will make the app full-screen. Inside any other layout widget it will take as much space as possible.

In addition to hosting a Game instance, the GameWidget also provides some structural support, with the following features:

It should be noted that GameWidget does not clip the content of its canvas, which means the game can potentially draw outside of its boundaries (not always, depending on which camera is used). If this is not desired, then consider wrapping the widget in Flutter's ClipRect.

Inheritance

Constructors

GameWidget({required T game, TextDirection? textDirection, GameLoadingWidgetBuilder? loadingBuilder, GameErrorWidgetBuilder? errorBuilder, WidgetBuilder? backgroundBuilder, Map<String, OverlayWidgetBuilder<T>>? overlayBuilderMap, List<String>? initialActiveOverlays, FocusNode? focusNode, bool autofocus = true, MouseCursor? mouseCursor, bool addRepaintBoundary = true, Key? key})
Renders the provided game instance.
GameWidget.controlled({required GameFactory<T> gameFactory, TextDirection? textDirection, GameLoadingWidgetBuilder? loadingBuilder, GameErrorWidgetBuilder? errorBuilder, WidgetBuilder? backgroundBuilder, Map<String, OverlayWidgetBuilder<T>>? overlayBuilderMap, List<String>? initialActiveOverlays, FocusNode? focusNode, bool autofocus = true, MouseCursor? mouseCursor, bool addRepaintBoundary = true, Key? key})
A GameWidget which will create and own a Game instance, using the provided gameFactory.
const

Properties

addRepaintBoundary bool
Whether the game should assume the behavior of a RepaintBoundary, defaults to true.
final
autofocus bool
Whether the focusNode requests focus once the game is mounted. Defaults to true.
final
backgroundBuilder WidgetBuilder?
Builder to provide a widget tree to be built between the game elements and the background color provided via Game.backgroundColor.
final
errorBuilder GameErrorWidgetBuilder?
If set, errors during the game loading will be caught and this widget will be shown. If not provided, errors are propagated normally.
final
focusNode FocusNode?
The FocusNode to control the games focus to receive event inputs. If omitted, defaults to an internally controlled focus node.
final
game → T?
The game instance which this widget will render, if it was provided with the default constructor. Otherwise, if the GameWidget.controlled constructor was used, this will always be null.
final
gameFactory GameFactory<T>?
A function that creates a Game that this widget will render.
final
hashCode int
The hash code for this object.
no setterinherited
initialActiveOverlays List<String>?
The list of overlays that will be shown when the game starts (but after it was loaded).
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder GameLoadingWidgetBuilder?
Builder to provide a widget which will be displayed while the game is loading. By default this is an empty Container.
final
mouseCursor MouseCursor?
The shape of the mouse cursor when it is hovering over the game canvas. This property can be changed dynamically via Game.mouseCursor.
final
overlayBuilderMap Map<String, OverlayWidgetBuilder<T>>?
A collection of widgets that can be displayed over the game's surface. These widgets can be turned on-and-off dynamically from within the game via the Game.overlays property.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textDirection TextDirection?
The text direction to be used in text elements in a game.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() GameWidgetState<T>
Renders a game in a flutter widget tree alongside widgets overlays.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited