sooxt98 / google_nav_bar

A modern google style nav bar for flutter.
MIT License
735 stars 114 forks source link

Make the state class _GNavState public #78

Open robertmrobo opened 2 years ago

robertmrobo commented 2 years ago

This is a PR of an issue in open a few minutes ago (#77 )

This allows me to do the following in my code:

  @override
  Widget build(BuildContext context) {
    final appBarKey = GlobalKey<GNavState>(); // This was not possible with the state being private

    const _kPages = <String, IconData>{
      'Home': Icons.home,
      'Explore': Icons.search,
      'Alerts': Icons.notifications,
      'Leagues': CommunityMaterialIcons.trophy
    };

    return Consumer(
      builder: (context, ref, child) {
        var currentPageIndex = ref.watch(bottomNavigationProvider); //My Navigation Drawer can update this value when a user clicks on a menu item on it

        if (currentPageIndex < _kPages.length) {
          appBarKey.currentState?.animateTo(currentPageIndex); // Now I can animate the bottom navigation drawer to the index which the navigation drawer is also pointing to
        }

        return GNav(
          key: appBarKey,
          tabs: buildGNavButtons(_kPages),
          activeColor: Colors.redAccent,
          gap: 8.0,
          onTabChange: (int i) =>SonicNavigator.navigateToPage(ref, i),
        );
      },
    );
  }
sooxt98 commented 2 years ago

@robertmrobo Hi there, i would suggest you to change Gnav.selectedIndex instead of modifying the actual navbar state directly. There's an example showing how changing tabpage trigger Gnav to change selectedIndex

https://github.com/sooxt98/google_nav_bar/blob/master/example/lib/main_advance.dart

YDA93 commented 1 year ago

@sooxt98 Please reconsider this PR.