【发布时间】:2023-03-11 06:49:01
【问题描述】:
该应用程序具有以下屏幕,
- 选项卡屏幕(主/主屏幕)
- CategoriesScreen(第一个选项卡屏幕)
- 最喜欢的屏幕(第二个标签屏幕)
- CategoryMealsScreen(CategoryScreen 的子屏幕)
我已经为每个屏幕构建方法添加了打印语句来检查导航,
当我从“CategoryMealsScreen”导航回“CategoriesScreen”时,我可以看到“CategoryMealsScreen”再次被调用,为什么会这样?
日志:
I/flutter (30320): TabsScreen ( parent screen )
I/flutter (30320): CategoriesScreen
I/flutter (30320): CategoryMealsScreen ( child screen, pressed back in this screen)
I/flutter (30320): CategoryMealsScreen ( child screen, once again it's being called after landing in CategoriesScreen)
I/flutter (30320): TabsScreen ( parent screen )
I/flutter (30320): CategoriesScreen
I/flutter (30320): CategoryMealsScreen ( child screen)
I/flutter (30320): CategoryMealsScreen ( child screen, once again it's being called after landing in CategoriesScreen)
I/flutter (30320): TabsScreen ( parent screen )
I/flutter (30320): CategoriesScreen
I/flutter (30320): TabsScreen
I/flutter (30320): FavoritesScreen
I/flutter (30320): TabsScreen ( parent screen )
I/flutter (30320): CategoriesScreen
I/flutter (30320): CategoryMealsScreen ( child screen)
I/flutter (30320): CategoryMealsScreen ( i pressed back button in-app bar and navigated back to parent screen but once again child screen was printed in logs )
下面是从 CategoriesScreen 推送 CategoryMealsScreen 的代码,
Navigator.of(ctx).pushNamed(
CategoryMealsScreen.routeName,
arguments: {
'id': id,
'title': title,
},
);
我的期望是当我导航回“TabsScreen”时不会再次调用“CategoryMealsScreen”
提前致谢。
【问题讨论】: