Flutter Android back按钮在Flatter中弹出另一个页面后没有调用onWillPop
我有一个Flutter Android back按钮在Flatter中弹出另一个页面后没有调用onWillPop,flutter,dart,flutter-navigation,Flutter,Dart,Flutter Navigation,我有一个BottomNavigationBar和一个IndexedStack,我试图在每个导航选项卡中实现嵌套导航。例如,“搜索”选项卡有自己的Navigator包装在WillPopScope中,如下所示: WillPopScope( onWillPop: () async { BottomNavigationBar navigationBar = navigationKey.currentWidget; if (Navigator.canPop(navigatorConte
BottomNavigationBar
和一个IndexedStack
,我试图在每个导航选项卡中实现嵌套导航。例如,“搜索”选项卡有自己的Navigator
包装在WillPopScope
中,如下所示:
WillPopScope(
onWillPop: () async {
BottomNavigationBar navigationBar = navigationKey.currentWidget;
if (Navigator.canPop(navigatorContext)) {
Navigator.pop(navigatorContext);
} else if (searchBarController.isOpen) {
searchBarController.close();
} else {
BottomNavigationBar navigationBar = navigationKey.currentWidget;
navigationBar.onTap(0);
}
return false;
},
child: Navigator(
onGenerateRoute: (settings) {
return MaterialPageRoute(
settings: settings,
builder: (context) {
switch (settings.name) {
case '/':
return buildRootPage();
case '/movie':
return MoviePage();
default:
return null;
}
},
);
},
),
);
将页面推到该搜索选项卡并弹出后,后退按钮不再调用onWillPop
方法,并且不会发生任何事情。然而,每当我点击屏幕上的任何地方,后退按钮就会再次开始工作
什么可能导致这种情况?确保Willposcope小部件是顶部小部件,而不是MaterialApp或Scaffold的子部件