Skip to content

Android Back Button Not Working On Any Tabs (Go_Router & ShellRoute) #139398

Open

Description

@jostney

Is there an existing issue for this?

Steps to reproduce

root
  - /welcome
  - /splash
  - /home
    - /explore
    - /dialogs
    - /notifications
    - /settings
  - /profile

App starts and decides which screen to start first with below

initialLocation: appManager.isFreshUser ? RoutePaths.welcome : RoutePaths.splash,

In both cases it navigates to home screen (With tabs explore, dialogs, notifications, settings) with below

router.go(RoutePaths.explore);

Expected results

The problem starts here, app do not close if physical back button and gives also zero reaction.
I want to close app(not kill) with back button when on home screen

Actual results

If we navigate to profile and then press back button, it goes back to home page. But the back button does not give reaction on home page.

Code sample

Code sample
final GlobalKey<NavigatorState> shellNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell');
final GlobalKey<NavigatorState> parentNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'parent');

final GoRouter router = GoRouter(
  debugLogDiagnostics: true,
  navigatorKey: parentNavigatorKey,
  initialLocation: appManager.isFreshUser ? RoutePaths.welcome : RoutePaths.splash,
  routes: [
    GoRoute(
      path: RoutePaths.welcome,
      parentNavigatorKey: parentNavigatorKey,
      builder: (context, state) => const WelcomeScreen(),
    ),
    GoRoute(
      path: RoutePaths.splash,
      parentNavigatorKey: parentNavigatorKey,
      builder: (context, state) => const SplashScreen(),
    ),
    ShellRoute(
      navigatorKey: shellNavigatorKey,
      builder: (context, state, child) {
        return HomeScreen();
      },
      routes: <RouteBase>[
        GoRoute(
          path: RoutePaths.explore,
          parentNavigatorKey: shellNavigatorKey,
          pageBuilder: (context, state) => const NoTransitionPage(
            child: ExploreScreen(),
          ),
        ),
        GoRoute(
          path: RoutePaths.dialogs,
          parentNavigatorKey: shellNavigatorKey,
          pageBuilder: (context, state) => NoTransitionPage(
            key: state.pageKey,
            child: const DialogsScreen(),
          ),
        ),
        GoRoute(
          path: RoutePaths.notifications,
          parentNavigatorKey: shellNavigatorKey,
          pageBuilder: (context, state) => NoTransitionPage(
            key: state.pageKey,
            child: const NotificationsScreen(),
          ),
        ),
        GoRoute(
          path: RoutePaths.settings,
          parentNavigatorKey: shellNavigatorKey,
          pageBuilder: (context, state) => NoTransitionPage(
            key: state.pageKey,
            child: const SettingsScreen(),
          ),
        ),
      ],
    ),
    GoRoute(
      path: RoutePaths.profile,
      parentNavigatorKey: parentNavigatorKey,
      builder: (context, state) => const ProfileScreen(),
    ),

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.1, on macOS 13.5.2 22G91 darwin-arm64, locale en-TR)
    • Flutter version 3.16.1 on channel stable at /Users/mee/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7f20e5d18c (4 days ago), 2023-11-27 09:47:30 -0800
    • Engine revision 22b600f240
    • Dart version 3.2.1
    • DevTools version 2.28.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/mee/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/mee/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.80.0)
    • VS Code at /Users/mee/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.78.0

[✓] Connected device (5 available)
    • MI 6 (mobile)              • 66eafcf3                             • android-arm64  • Android 9 (API 28)
    • Mee’s IPhone (mobile)  • 00008101-0006014A2278001E            • ios            • iOS 17.1.1 21B91
    • iPhone 11 Pro Max (mobile) • E6D4F26D-A7CA-4FB6-86FE-B9DBAB77F575 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 119.0.6045.199

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. darshankawar commented on Dec 4, 2023

    @darshankawar
    Member

    @jostney
    Can you take a look at this issue and see if it resembles your case or not ?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 4, 2023
  3. jostney commented on Dec 4, 2023

    @jostney
    Author
    root
      - /welcome (parent navigator key) 
      - /splash (parent navigator key)
      - /home 
        - /explore (shell navigator key) (Back Button DOES NOT Work) ❌
        - /dialogs (shell navigator key) (Back Button DOES NOT Work) ❌
        - /notifications (shell navigator key) (Back Button DOES NOT Work) ❌
        - /settings (shell navigator key) (Back Button DOES NOT Work) ❌
      - /profile (parent navigator key) (Back Button Works) ✅
      - /conversation (parent navigator key) (Back Button Works) ✅
    

    I have looked the issue, but mine issue is not for whole app itself, just for screens with shell router

    Above is general path of the app, basically it starts with welcome --> splash --> home

    The home screen hosts for explore, dialogs, notifications, settings screens

    User can navigate from dialogs to conversation screen like in WhatsApp, in this case it can able to navigate back via physical back button. But the back button does not function on explore, dialogs, notifications, settings tabs. It must close the app (okay not kill)

    I'm sure i never integrate something WillPopScope or etc on in the app, which can block the back behaviour.

    Hopefully i implemented a workaround for this and its working (But the problem still existing actually)

    class AppBackButtonDispatcher extends RootBackButtonDispatcher {
      AppBackButtonDispatcher._internal({
        required GoRouter goRouter,
      }) : xGoRouter = goRouter {
        _goRouterDelegate = xGoRouter.routerDelegate;
      }
    
      late final GoRouter xGoRouter;
      late final RouterDelegate _goRouterDelegate;
      DateTime oldTime = DateTime.now();
      DateTime newTime = DateTime.now();
    
      static final AppBackButtonDispatcher _instance = AppBackButtonDispatcher._internal(
        goRouter: router,
      );
    
      factory AppBackButtonDispatcher.getInstance() {
        return _instance;
      }
      @override
      Future<bool> didPopRoute() async {
        var context = xGoRouter.routerDelegate.navigatorKey.currentContext!;
    
        final mathcList = _goRouterDelegate.currentConfiguration as RouteMatchList;
        if (mathcList.matches.firstWhereOrNull((e) => e is ImperativeRouteMatch) == null) {
          newTime = DateTime.now();
          var difference = newTime.difference(oldTime).inMilliseconds;
          oldTime = newTime;
          if (difference < 1000) {
            hideSnackBar(context);
            return false;
          } else {
            showSnackBar(context);
            return true;
          }
        } else {
          router.pop();
          return true;
        }
      }
    
      void showSnackBar(BuildContext context) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            behavior: SnackBarBehavior.floating,
            duration: const Duration(milliseconds: 600),
            content: Text(i10n.tap_to_exit),
          ),
        );
      }
    
      void hideSnackBar(BuildContext context) {
        ScaffoldMessenger.of(context).hideCurrentSnackBar();
      }
    }
    
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 4, 2023
  5. darshankawar commented on Dec 5, 2023

    @darshankawar
    Member

    Thanks for the update. Seeing the same behavior as reported.

    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.16.0, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.16.0 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db7ef5bf9f (12 days ago), 2023-11-15 11:25:44 -0800
        • Engine revision 74d16627b9
        • Dart version 3.2.0
        • DevTools version 2.28.2
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.18.0-2.0.pre.22, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.18.0-2.0.pre.22 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision bfaacd5ef8 (81 minutes ago), 2023-12-04 22:48:25 -0500
        • Engine revision f43ef6cbdd
        • Dart version 3.3.0 (build 3.3.0-190.0.dev)
        • DevTools version 2.30.0
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/dhs/Library/Android/sdk
        ✗ cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/macos#android-setup for
          more details.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA.app
        • Flutter plugin version 65.1.4
        • Dart plugin version 213.7228
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 15.3.1 19D52
        • macOS (desktop)           • macos                                    •
          darwin-x64     • macOS 12.2.1 21D62 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 109.0.5414.119
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
          
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    
  6. added
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Dec 5, 2023
  7. added
    P1High-priority issues at the top of the work list
    on Dec 7, 2023
  8. 14 remaining items

  9. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Feb 28, 2025
  10. flutter-triage-bot commented on Oct 11, 2025

    @flutter-triage-bot

    This issue is marked P1 but has had no recent status updates.

    The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

    Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

  11. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions