当我从最终视图返回到“初始视图”时,所有3 State
中的每个BlocProviders
被保存。
我的代码在这里链接: GIST
我不知道自己缺少什么,在第一次运行时一切正常。
但是,当我回到InitialView
时回到GameView
时,请重新设置所有内容并再次移至GameModeSelectionView,它被多次调用(状态以某种方式保存而不是转储??)(1):
flutter: State of GameSelectionState GameSelectionInitial
flutter: State of GameSelectionState GameSelectionStart
flutter: State of QuestionState StopQuestion
flutter: OK?
flutter: State of GameSelectionState GameSelectionStart
flutter: State of QuestionState StopQuestion
flutter: OK?
flutter: State of GameSelectionState GameSelectionStart
flutter: State of QuestionState StopQuestion
flutter: OK?
flutter: State of GameSelectionState GameSelectionInitial
此过程随着每次迭代(1)
我正在使用flutter_bloc依赖项: https://pub.dev/packages/flutter_bloc
答案 0 :(得分:0)
我使用MaterialPageRoute
onGenerateRoute
解决了该问题(因为我需要动态路由)
我将Buttons onPressed
方法中的代码替换为:
Navigator.of(context).pushReplacementNamed(
GameModeSelectionView.routeName,
arguments: players);
像魅力一样运转,不再生长一棵树。