flame
flame copied to clipboard
[flame_riverpod] "Null check operator used on a null value" on onMount() again
Current bug behavior
Exception when compement onMount() in RiverpodComponentMixin
Expected behavior
Not exception
Steps to reproduce
use the RouterComponent to jump among two routes
- setup two pages and navigate between them
world.add(
router = RouterComponent(
routes: {
'home': Route(HomePage.new, maintainState: true),
'play': Route(PlayPage.new, maintainState: true),
},
initialRoute: 'home',
),
);
class HomePage extends Component
with HasGameReference<TestGame>, RiverpodComponentMixin {
}
class PlayPage extends Component
with HasGameReference<TestGame>, RiverpodComponentMixin {
}
Flutter doctor output
Output of: flutter doctor -v
More environment information
- Flame version: 1.14.0
Log information
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════
The following _TypeError was thrown during a scheduler callback:
Null check operator used on a null value
When the exception was thrown, this was the stack:
#0 RiverpodComponentMixin.onMount (package:flame_riverpod/src/consumer.dart:99:13)
#1 PlayPage.onMount (package:red_twine/pages/play.dart:50:11)
#2 Component._mount (package:flame/src/components/core/component.dart:889:5)
#3 Component.handleLifecycleEventAdd (package:flame/src/components/core/component.dart:805:7)
#4 ComponentTreeRoot.processLifecycleEvents (package:flame/src/components/core/component_tree_root.dart:92:28)
More information
if set maintainState = false , the exception is missing.
Route(HomePage.new, maintainState: false)
review codes, ref.game will be set null when onRemove. But onLoad() will never been invoked under "maintainState: true" in Route - keep a component instance, and removed and re-mounted the compoment again,