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
47 stars 48 forks source link

Android back button results in blank screen: can't block with popscope #139

Closed BarryCarlyon closed 3 months ago

BarryCarlyon commented 3 months ago

Package Version (from pubspec.yaml): persistent_bottom_nav_bar: ^5.0.0

Bug Description

If you navigate backwards from the home page of an app using the android back button you get black screen Press it again goes to another app/home page as expected.

The black screen shouldn't exist

Additionally, PopScope would be used to block the back button functioning and it doesn't when you wrap persistennav in a PopScope

To Reproduce

Steps to reproduce the behavior:

  1. Launch you app
  2. Use the Android back button, either hardward or software versions
  3. Be pressnted with a blank page

This can result in an error message/console error messages as it's a totally unexpected state

as per my rubber ducking in https://github.com/jb3rndt/PersistentBottomNavBarV2/issues/137#issuecomment-2032944561

Expected behavior

Code to reproduce

This will block back working from the home page

    return ChangeNotifierProvider(
        create: (context) => ApiService(),
        child: PopScope(
            canPop: false,
            child: HomePageBuild()
        )
    );

This does not:

HomePageBuild in this case is my first tab in buildTabs.

    return ChangeNotifierProvider(
        create: (context) => ApiService(),
        child: PopScope(
            canPop: false,
            child: PersistentTabView(
          tabs: _buildTabs(),

          navBarOverlap: const NavBarOverlap.none(),
          navBarBuilder: (navBarConfig) => Style3BottomNavBar(
            navBarConfig: navBarConfig,
            navBarDecoration: const NavBarDecoration(
              color: superdarkRed,
            ),
          ),
          backgroundColor: superdarkRed,
        )
      )
    );

With or without popscope the blank page occurs

    return ChangeNotifierProvider(
      create: (context) => ApiService(),
      child: PersistentTabView(
        tabs: _buildTabs(),

        navBarOverlap: const NavBarOverlap.none(),
        navBarBuilder: (navBarConfig) => Style3BottomNavBar(
          navBarConfig: navBarConfig,
          navBarDecoration: const NavBarDecoration(
            color: superdarkRed,
          ),
        ),
        backgroundColor: superdarkRed,
      )
    );

Screenshots

After hitting the back soft key on the android "remote control" so a physical pixel 6 device here

image

If I hot reload/hit sync files I can force this error, if I'm on the blank page.

image
BarryCarlyon commented 3 months ago

I added:

    PersistentTabController _controller = PersistentTabController(initialIndex: 0);
    _controller.addListener(() {
      debugPrint('we be navin');
    });

snip

      child: PersistentTabView(
        controller: _controller,

And I don't get a "we be naving" when we go to the blank screen

jb3rndt commented 3 months ago

Hi, thank you for providing all the information. I'm pretty sure I finally found the issue. When migrating the internal WillPopScope to PopScope, the final navigator pop (which causes the black page) does not minimize the app like it used to when returning true from WillPopScope. I just released version 5.2.0 which should contain the fix. Now, a PopScope with canPop: false that wraps the PersistentTabView should also work. Feel free to check it out, I will keep this open for now in case there are still issues with that.

BarryCarlyon commented 3 months ago

Without popscope: we navigated out of the app and no blank screen With popscope: navigation was blocked out of the app and no blank screen

Looks fixed to me!