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

AutoTabsScaffold dynamic add #2117

Open
JamieYee opened this issue Dec 26, 2024 · 0 comments
Open

AutoTabsScaffold dynamic add #2117

JamieYee opened this issue Dec 26, 2024 · 0 comments

Comments

@JamieYee
Copy link

 @override
  Widget build(BuildContext context, WidgetRef ref) {
    final accountEnable = ref.watch(configNotifierProvider.select((it) => it.accountEnable));

    final List<PageRouteInfo> routes = [
      HomeRoute(),
      TrendRoute(),
      if(accountEnable)AccountRoute(),
      MineRoute()
    ];

    final tabs = [
      NavigationDestination(icon: Icon(Icons.home), label: 'detail'.tr()),
      NavigationDestination(icon: Icon(Icons.trending_up), label: 'trend'.tr()),
      if(accountEnable)NavigationDestination(icon: Icon(Icons.credit_card), label: 'account'.tr()),
      NavigationDestination(icon: Icon(Icons.person), label: 'mine'.tr()),
    ];

    return AutoTabsScaffold(
      key: _tabsRouterKey,
      routes: routes,
      bottomNavigationBuilder: (_, tabsRouter) {
        return ScrollToHide(
            child: NavigationBar(
                onDestinationSelected: (index) =>
                    tabsRouter.setActiveIndex(index),
                selectedIndex: tabsRouter.activeIndex,
                destinations: tabs),
            height: Platform.isAndroid ? 80.w : 85.w,
            scrollController: _scrollController,
            duration: Duration(milliseconds: 300),
            hideDirection: Axis.vertical);
      },
    );
  }

I control whether accountEnable is turned on in the subpage of MineRoute. If the operation is turned on, then the destinations under AccountRoute are displayed as NavigationDestination(icon: Icon(Icons.person), label: 'mine'.tr()). You need to click other destinations again to return to normal. If it is turned from on to off, there is no problem

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

No branches or pull requests

1 participant