-
Notifications
You must be signed in to change notification settings - Fork 30.2k
GoRouter / StatefulShell: Lost navigation history when changing top branch / inconsistent behavior with android system back button #156400
Description
Steps to reproduce
- run the official example code on Android
- click
View detailsunderScreen A=>Details for Aopens - Here, tapping the top left back button or using the Android native back button will have the same behavior => popping the
Detailsscreen and go back toScreen A.
No problem here, and it feels normal and intuitive. - From step 2. , have a quick glance at the tab
Section Band go back to tabSection A - Now, tapping the top left back button or using the Android native back button have different behaviors:
- using the top left button keeps the same behavior as before, no problem.
- using the system button acts like it forgot the stack/history and considers
Details of Aas the topmost page ofSection Aand therefor closes the app.
Expected results
Step 3. should behave as step 5., for consistency with each other and with what the user expects: the navigation stack should be restored when switching back to the same tab.
It also makes the two available back buttons inconsistent with each other when on step 5.
This is very surprising, and I don't see how to work around this. I haven't shipped my app to users yet, but already, I myself can't help but accidentally close my app all the time because the muscle memory for the expected behavior is so strong :-/
I think this is a bug and not on purpose also because the documentation of StatefulShellRoute (and other places I think) mentions that:
The StatefulNavigationShell can be used to access information about the state of the route, as well as to switch the active branch (i.e. restoring the navigation stack of another branch). The latter is accomplished by using the method [StatefulNavigationShell.goBranch](https://pub.dev/documentation/go_router/latest/go_router/StatefulNavigationShell/goBranch.html)...
Actual results
Code sample
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.24.1, on NixOS 24.05 (Uakari) 6.10.12, locale en_US.UTF-8)
• Flutter version 3.24.1 on channel stable at /nix/store/ivslg1wbqmfcfhaxabdi36bd3cjvhnbq-flutter-wrapped-3.24.1-sdk-links
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision nixpkgs000 (), 1970-01-01 00:00:00
• Engine revision c9b9d5780d
• Dart version 3.5.1
• DevTools version 2.37.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /nix/store/x428bw3jdbqgy2pdapqnpqh6k3v75cy1-androidsdk/libexec/android-sdk
• Platform android-34, build-tools 30.0.3
• ANDROID_HOME = /nix/store/x428bw3jdbqgy2pdapqnpqh6k3v75cy1-androidsdk/libexec/android-sdk
• ANDROID_SDK_ROOT = /nix/store/x428bw3jdbqgy2pdapqnpqh6k3v75cy1-androidsdk/libexec/android-sdk
• Java binary at: /nix/store/xy53lk4001h814d7dwh8f52wcqxrn7rp-openjdk-17.0.11+9/lib/openjdk/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.11+9-nixos)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /nix/store/2jnylk8yf0mrhh0ja5ffcylcxzc5jpf3-google-chrome-128.0.6613.137/bin/google-chrome-stable
[✓] Linux toolchain - develop for Linux desktop
• clang version 16.0.6
• cmake version 3.29.6
• ninja version 1.12.1
• pkg-config version 0.29.2
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/to/linux-android-setup for detailed instructions).
[✓] Connected device (3 available)
• Pixel 7 Pro (mobile) • 192.168.1.13:43079 • android-arm64 • Android 15 (API 35)
• Linux (desktop) • linux • linux-x64 • NixOS 24.05 (Uakari) 6.10.12
• Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.137
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.