echedev / theseus-navigator

Theseus Navigator is a Flutter navigation package. It is based on Flutter Navigator 2.0 / Router API, and offers declarative navigation scheme, easy API, supports deeplinks, nested navigators and more.
MIT License
6 stars 1 forks source link

Duplicate global key when tapping back #13

Closed rebaz94 closed 2 years ago

rebaz94 commented 2 years ago

Hi, thanks for your great library. When I test example app, I detected wired issue sometime appear when tapping on the back button mainly when going to LoginScreen here is the video that issue appears

https://user-images.githubusercontent.com/11982812/144476092-699fa0fa-bde1-46bc-b627-f58f0ff45b8d.mov

here the error

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Builder:
Assertion failed: file:///Users/rebo/fvm/versions/master/packages/flutter/lib/src/widgets/navigator.dart:3446:18
!keyReservation.contains(key)
is not true

or

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Builder:
A GlobalKey was used multiple times inside one widget's child list.

The offending GlobalKey was: [LabeledGlobalKey<NavigatorState>#ab259 Root]
The parent of the widgets with that key was: Builder
The first child to get instantiated with that key became: Navigator-[LabeledGlobalKey<NavigatorState>#ab259 Root]
  dirty
  dependencies: [UnmanagedRestorationScope, HeroControllerScope]
  state: NavigatorState#668dd(tickers: tracking 2 tickers)
The second child that was to be instantiated with that key was: Builder
A GlobalKey can only be specified on one widget at a time in the widget tree.

note: I changed the MainScreen code to not use overlay, after these changes the issue appear, I expected that it should work without OverlayEntry

modified code

class MainScreen extends StatefulWidget {
  const MainScreen({
    Key? key,
    required this.content,
    required this.onSelectBottomTab,
    required this.selectedIndex,
  }) : super(key: key);

  final Widget content;

  final void Function(int) onSelectBottomTab;

  final int selectedIndex;

  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: widget.content,
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home_rounded),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.list_rounded),
            label: 'Catalog',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.more_horiz_rounded),
            label: 'Settings',
          ),
        ],
        // selectedItemColor: Constants.colorAccent,
        // unselectedItemColor: Constants.colorUnselected,
        currentIndex: widget.selectedIndex,
        onTap: widget.onSelectBottomTab,
      ),
    );
  }
}

Is it a bug or I missed something? Thanks

rebaz94 commented 2 years ago

Hi @echedev I found the bug and fixed but I don't know if its a right solution or not. and it work perfectly.

Please could you check this Fix duplicate key

If its good, I can make a PR :)

echedev commented 2 years ago

Hi @rebaz94 Thank you for the feedback and suggested solution for the issue. I made this PR https://github.com/echedev/theseus-navigator/pull/14 to fix this bug. Please check if it work.

rebaz94 commented 2 years ago

Thanks for your fix, yes it working properly

rebaz94 commented 2 years ago

@echedev I think the problem is still exist but its very weird sometime happen in some condition

echedev commented 2 years ago

Hi, thank you for checking this. I will look into it more.

On Sun, Dec 5, 2021 at 2:02 PM Rebaz Raouf @.***> wrote:

@echedev https://github.com/echedev I think the problem is still exist but its very weird sometime happen in some condition

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/echedev/theseus-navigator/issues/13#issuecomment-986208851, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3PLNJ2FC4O67HMGVDO6KLUPNBD3ANCNFSM5JHXWSJQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.