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

Make the state class _GNavState public #78

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

robertmrobo
Copy link

@robertmrobo robertmrobo commented Apr 12, 2022

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
Copy link
Owner

sooxt98 commented Apr 15, 2022

@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
Copy link

YDA93 commented Oct 19, 2022

@sooxt98 Please reconsider this PR.

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

Successfully merging this pull request may close these issues.

3 participants