jb3rndt / PersistentBottomNavBarV2

A highly customizable persistent bottom navigation bar for Flutter
https://pub.dev/packages/persistent_bottom_nav_bar_v2
BSD 3-Clause "New" or "Revised" License
49 stars 56 forks source link

[Bug]: popAllScreensOnTapAnyTabs is not working #171

Closed kawi15 closed 4 months ago

kawi15 commented 5 months ago

Version

5.2.3

Flutter Doctor Output

[!] Flutter (Channel [user-branch], 3.19.0, on Microsoft Windows [Version 10.0.22631.3593], 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 (4 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.3593]
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 125.0.6422.142
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 125.0.2535.92

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

! Doctor found issues in 3 categories.

What platforms are you seeing the problem on?

Android, iOS

What happened?

When I set popAllScreensOnTapAnyTabs = true I expect to open initial page of tab. This is not happening. Page is opening with all the pages opened on this tab.

Steps to reproduce

  1. Go to tab 1
  2. Open nested page in this tab
  3. Go to tab 2
  4. Tap tab 1
  5. Expect to see first screen, but actually it's that opened nested page

Code to reproduce the problem

import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';

void main() => runApp(PersistenBottomNavBarDemo());

class PersistenBottomNavBarDemo extends StatelessWidget {

  PersistentTabController pageController = PersistentTabController(initialIndex: 0);
  BuildContext? selectedTabContext;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Persistent Bottom Navigation Bar Demo',
      home: PersistentTabView(
        controller: pageController,
        navBarHeight: 70,
        handleAndroidBackButtonPress: true,
        popAllScreensOnTapAnyTabs: true,
        stateManagement: true,
        selectedTabContext: (context) => selectedTabContext = context,
        tabs: [
          PersistentTabConfig(
            screen: YourFirstScreen(),
            item: ItemConfig(
              icon: Icon(Icons.home),
              title: "Home",
            ),
          ),
          PersistentTabConfig(
            screen: YourSecondScreen(),
            item: ItemConfig(
              icon: Icon(Icons.message),
              title: "Messages",
            ),
          ),
        ],
        navBarBuilder: (navBarConfig) => Style1BottomNavBar(
          navBarConfig: navBarConfig,
        ),
      ),
    );
  }
}

class YourFirstScreen extends StatelessWidget {
  const YourFirstScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (context) => const ExampleOne()));
          },
          child: Text('Go to Example One')
      )
    );
  }
}

class YourSecondScreen extends StatelessWidget {
  const YourSecondScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(child: Text('Second screen'));
  }
}

class ExampleOne extends StatelessWidget {
  const ExampleOne({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(child: Text('Nested Page Example One'));
  }
}

As I saw in source code, there is no difference between popAllScreensOnTapAnyTabs and popAllScreensOnTapOfSelectedTab I am not sure about this but popAllScreensOnTapAnyTabs is doing the same thing as popAllScreensOnTapOfSelectedTab as in source code if any of this is true it's executing the same code.

Relevant log output

No response

Screenshots

No response

jb3rndt commented 5 months ago

Hi, thank you for reporting this. You are right there is an issue in the code. The fix will be included in the next release

jb3rndt commented 4 months ago

The fix is included in version 5.3.0