Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Android back button switching tabs depending on history when set to true #180

Open
kawi15 opened this issue Sep 13, 2024 · 2 comments

Comments

@kawi15
Copy link

kawi15 commented Sep 13, 2024

Version

5.2.3

Flutter Doctor Output

[!] Flutter (Channel [user-branch], 3.19.0, on Microsoft Windows [Version 10.0.22631.4037], locale pl-PL)
    ! Flutter version 3.19.0 on channel [user-branch] at C:\Users\KarolW\Documents\flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision bae5e49bc2 (7 months ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at C:\Users\KarolW\AppData\Local\Android\sdk
    • Platform android-34, build-tools 32.0.0
    • Java binary at: C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
    • Java version Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[!] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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
    X Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[√] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Version 10.0.22631.4037]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 128.0.6613.138
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 128.0.2739.42

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

What platforms are you seeing the problem on?

Android

What happened?

When handleAndroidBackButtonPress is set to true android back button should back to first tab everytime is on other tab and all screens on this tab are popped as said here:

2. If you are on another tab with all screens popped of that given tab, you will be switched to first tab.

and actually when you switch between tabs back button is going back to previous tab, not to first tab

and also when I am on 1st tab, change to 2nd tab and change again to 1st tab using BottomNavBar then back button will go back to 2nd tab instead of closing app

If the you are on the first tab with all screens popped of the given tab, the app will close

Steps to reproduce

4 tabs example

  1. You are in first tab, go to 2nd tab

  2. Go to 3rd tab

  3. Go to 4th tab

  4. Press back
    Expectation: App is going back to first tab
    Reality: App is going back to 3rd tab

  5. Press back again - app is going back to 2nd tab

2 tabs example, other case

  1. You are in 1st tab, change to 2nd tab
  2. Change to 1st tab, tapping on BottomNavBar item
  3. Press back button - it will go to 2nd tab instead of closing app

Code to reproduce the problem

PersistentTabView(
      controller: pageController,
      navBarHeight: 70,
      handleAndroidBackButtonPress: true,
      popAllScreensOnTapAnyTabs: false,
      stateManagement: true,
      resizeToAvoidBottomInset: false,
      navBarBuilder: (navBarConfig) => Style4BottomNavBar(),
      onTabChanged: (index) {
        setState(() {
          currentIndex = index;
        });
      }
)

Relevant log output

No response

Screenshots

No response

@TMuthu
Copy link

TMuthu commented Sep 16, 2024

facing same issue.

@jb3rndt
Copy link
Owner

jb3rndt commented Sep 16, 2024

TL;DR: If you want that behavior back: set PersistentTabController.historyLength = 1.

Hi, sorry I forgot to adjust the documentation for that. In this PR (#138) the tabs history behavior was changed to be more adjustable. By default, the last five tabs the user visited will be remembered so that the user can go back through them using the Android back button. By setting the PersistentTabController.historyLength to 1, the history will always solely contain the initial tab and thus switch to it and exit or directly exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants