Android back button is not calling onWillPop after popping another page in Flutter


I have a BottomNavigationBar with an IndexedStack and I’m trying to implement nested navigation inside each navigation tab. For example, "search" tab has its own Navigator wrapped in a WillPopScope like following:

  onWillPop: () async {
    BottomNavigationBar navigationBar = navigationKey.currentWidget;
    if (Navigator.canPop(navigatorContext)) {
    } else if (searchBarController.isOpen) {
    } else {
      BottomNavigationBar navigationBar = navigationKey.currentWidget;
    return false;
  child: Navigator(
    onGenerateRoute: (settings) {
      return MaterialPageRoute(
        settings: settings,
        builder: (context) {
          switch ( {
            case '/':
              return buildRootPage();
            case '/movie':
              return MoviePage();
              return null;

After pushing a page to this search tab and popping it, back button no longer calls onWillPop method and nothing happens. However, back button starts to work again whenever I click anywhere on the screen.

What can possibly cause this?


make sure that WillPopScope Widget is the top widget not the child of MaterialApp or Scaffold

Answered By – biruk IS

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *