Dealing with BuildContext
in a Flame Game
can be challenging because:
GameWidget
is who own itGame
after it is attached to the GameWidget
, so it is no ready on onLoad
or onMount
as one could expectHaving an easy access to the BuildContext
opens many possibilities to the users, like readying ThemeData, a Bloc, l10n, etc.
None come to mind.
A suggestion that I can think of, is an idea kind in line with how the Builder
widget works for Flutter.
Idea 1:
gameRef.withContext((context) {
// ...
});
The closure passed will be executed right way if the game is already attached, and if not, it will be queued for execution once the attachment happens.
Idea 2:
For this idea we would need #1522 to be working.
add(
BuildContextComponent(
children: [
MyComponent(),
],
);
);
That component would hook itself somehow on the game attachment and once the game is attached, it will add the components to the component three.
We probably don't really need #1522 for this to already have some value, but I it really shinning with we get that declarative API working.
Also I don't think one idea excludes the other, both could live together so the user could choose whatever makes more sense for their context.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too