Flutter Bloc - Widget 树不断生长

Flutter Bloc - Widget tree growing endlessy

当我从最终视图返回到我的 "initial view" 时,所有 3 个 BlocProviders 中的每个 State 都被保存。

查看小部件树:

我的代码链接在这里: GIST

我不明白我错过了什么,一开始 运行 一切正常。

但是,当我在 GameView 中返回 InitialView 时,重新设置所有内容并再次移动到 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

我使用 MaterialPageRoute onGenerateRoute 解决了这个问题(因为我需要动态路由)

我将按钮 onPressed 方法中的代码替换为喜欢:

Navigator.of(context).pushReplacementNamed(
              GameModeSelectionView.routeName,
              arguments: players);

像魅力一样工作,不再长树。