0

当我从最终视图返回到我的“初始视图”State时,所有 3 个视图中的每一个都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

4

1 回答 1

0

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

我将 ButtonsonPressed方法中的代码替换为:

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

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

于 2020-02-16T11:27:50.970 回答