In addressing https://github.com/flame-engine/flame/issues/2403, this PR removes the game widget `onRemove` call which was technically locked into an internal method and places the call in `FlameGame` that can then be triggered by `Game` which can be triggered by `GameRenderBox.detach`. So why not use `dispose` as was discussed in the issue? I would refer to the Flutter API docs: https://api.flutter.dev/flutter/widgets/State/dispose.html _Called when this object is removed from the tree permanently._ _The framework calls this method when this [State](https://api.flutter.dev/flutter/widgets/State-class.html) object will never build again. After the framework calls [dispose](https://api.flutter.dev/flutter/widgets/State/dispose.html), the [State](https://api.flutter.dev/flutter/widgets/State-class.html) object is considered un[mounted] (https://api.flutter.dev/flutter/widgets/State/mounted.html) and the mounted property is false. It is an error to call [setState](https://api.flutter.dev/flutter/widgets/State/setState.html) at this point. This stage of the lifecycle is terminal: there is no way to remount a [State](https://api.flutter.dev/flutter/widgets/State-class.html) object that has been disposed._ So, the issue comes down to you may be removing a `FlameGame` but not want it permanently destroyed. Since you need the state maintained, then by naming the method `dispose()`, users would think it permanently destroys the game. So, this keeps it with `onRemove` and thus inline with user expectations imo. A user simply needs to override `onRemove` and set `FlameGame.disposeAll = true` then call `super.onRemove()` which did not exist previously for `FlameGame`; thus, I do not think this is a breaking change. ```dart @override void onRemove() { disposeAll = true; super.onRemove(); } ``` Currently, due to my lack of knowledge of bloc, the test is not working as the game is never mounted, so I am posting the PR in order to get some assistance with that. I tried to use the exact code that was originally posted in the issue, so we can validate the fix resolves that specific leak. This code currently passes all tests and the behavior when stepping through the code, is as would be expected for the life cycle. I am hoping @imaNNeo can take a look at the test and provide some pointers.
A Flutter-based game engine.
Documentation
The full documentation for Flame can be found on docs.flame-engine.org.
To change the version of the documentation, use the version selector noted with version: in the
top of the page.
Note: The documentation that resides in the main branch is newer than the released documentation on the docs website.
Other useful links:
- The official Flame site.
- Examples of most features which can be tried out from your
browser.
- To access the code for each example, press the
< >button in the top right corner.
- To access the code for each example, press the
- Tutorials - Some simple tutorials to get started.
- API Reference - The generated dartdoc API reference.
- awesome-flame - A curated list of Tutorials, Games, Libraries and Articles.
Help
There is a Flame community on Blue Fire's Discord server where you can ask any of your Flame related questions.
If you are more comfortable with StackOverflow, you can also create a question there. Add the Flame tag, to make sure that anyone following the tag can help out.
Features
The goal of the Flame Engine is to provide a complete set of out-of-the-way solutions for common problems that games developed with Flutter might share.
Some of the key features provided are:
- A game loop.
- A component/object system (FCS).
- Effects and particles.
- Collision detection.
- Gesture and input handling.
- Images, animations, sprites, and sprite sheets.
- General utilities to make development easier.
On top of those features, you can augment Flame with bridge packages. Through these libraries, you will be able to access bindings to other packages, including custom Flame components and helpers, in order to make integrations seamless.
Flame officially provides bridge libraries to the following packages:
- flame_audio for AudioPlayers: Play multiple audio files simultaneously.
- flame_bloc for Bloc: A predictable state management library.
- flame_fire_atlas for FireAtlas: Create texture atlases for games.
- flame_forge2d for Forge2D: A Box2D physics engine.
- flame_lint -
Our set of linting (
analysis_options.yaml) rules. - flame_oxygen for Oxygen: A lightweight Entity Component System (ECS) framework.
- flame_rive for Rive: Create interactive animations.
- flame_svg for flutter_svg: Draw SVG files in Flutter.
- flame_tiled for Tiled: 2D tile map level editor.
Sponsors
The Flame Engine's top sponsors:
Do you or your company want to sponsor Flame? Check out our OpenCollective page, which is also mentioned in the section below, or contact us on Discord.
Support
The simplest way to show us your support is by giving the project a star! ⭐
You can also support us monetarily by donating through OpenCollective:
Through GitHub Sponsors:
Or by becoming a patron on Patreon:
You can also show on your repository that your game is made with Flame by using one of the following badges:
[](https://flame-engine.org)
[](https://flame-engine.org)
[](https://flame-engine.org)
Contributing
Have you found a bug or have a suggestion of how to enhance Flame? Open an issue and we will take a look at it as soon as possible.
Do you want to contribute with a PR? PRs are always welcome, just make sure to create it from the correct branch (main) and follow the checklist which will appear when you open the PR.
For bigger changes, or if in doubt, make sure to talk about your contribution to the team. Either via an issue, GitHub discussion, or reach out to the team either using the Discord server.
Credits
- The Blue Fire team, who are continuously working on maintaining and improving Flame and its ecosystem.
- All the friendly contributors and people who are helping out in the community.

