Skip to content

Make the state class _GNavState public#78

Open
robertmrobo wants to merge 5 commits intosooxt98:masterfrom
robertmrobo:master
Open

Make the state class _GNavState public#78
robertmrobo wants to merge 5 commits intosooxt98:masterfrom
robertmrobo:master

Conversation

@robertmrobo
Copy link
Copy Markdown

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

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