auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

AutoTabsRouter is not invoking builder when children are pushed inside tab

Open yevyevyev opened this issue 2 years ago • 8 comments

Hi, the issue name is self-explanatory. Why this matters - I want to hide the bottom tab bar when a specific route is being pushed but it does not invoke the build method. Maybe for this specific case to hide the bottom tab bar it would nice to provide a callback which is invoked each time the navigation stack is updated?

yevyevyev avatar Oct 22 '21 12:10 yevyevyev

Im having the same issue with trying to conditionally set the leading attribute on the AppBar. Not found any solutions but would be interested in the solution

lloydrichards avatar Oct 22 '21 12:10 lloydrichards

@tapkain @lloydrichards if you watch any router you'll get a rebuild everytime the stack changes.

context.watchRouter.topRoute;
// or
context.watchTabsRouter.topRoute;

what I usually do is watch the topRoute directly final hideNavBar = context.topRoute.name == FullScreenRoute.name;

Milad-Akarie avatar Oct 22 '21 13:10 Milad-Akarie

I have this tabs router

AutoTabsScaffold(
      homeIndex: 0,
      routes: const [
        ExploreTab(),
        RadarTab(),
        CreatePostTab(),
        NotificationsTab(),
        CurrentUserTab(),
      ],
      bottomNavigationBuilder: (context, tabsRouter) {
        if (context.topRouteMatch.meta[kHideBottomBar] == true) {
          return const SizedBox.shrink();
        }
        return HomeBottomNavigationBar(
          tabsRouter: tabsRouter,
        );
      },
    );

routes declarations

 AutoRoute<void>(
          initial: true,
          page: HomePage,
          guards: [AuthGuard],
          children: [
            AutoRoute<void>(
              name: 'ExploreTab',
              page: EmptyRouterPage,
              children: [
                AutoRoute<void>(page: ExploreBinding, initial: true),
                AutoRoute<void>(page: TopUsersBinding),
                AutoRoute<void>(page: TopMoodsBinding),
                AutoRoute<void>(page: UserBinding),
                AutoRoute<void>(page: MoodBinding),
                AutoRoute<void>
                  page: RatePostBinding,
                  meta: <String, dynamic>{
                    kHideBottomBar: true,
                  },
                ),
              ],
            ),
            ...other children here

topRoute extension for context is already watching router btw. When I'm pushing RatePostBinding which had the meta property, no bottomNavigationBuilder is invoked. So this is the issue in a nutshell.

yevyevyev avatar Oct 22 '21 13:10 yevyevyev

@tapkain guess I'm gonna make both appBar and bottomNavigation builders rebuild on global stack changes.

Milad-Akarie avatar Oct 22 '21 15:10 Milad-Akarie

@tapkain check out the new version auto_route: 3.0.2

please close if this resolves your issue.

Milad-Akarie avatar Oct 22 '21 15:10 Milad-Akarie

tried 3.03, still does not trigger the method. from what I see, the main change was this line, right? final parentScope = RouterScope.of(context, watch: true);

yevyevyev avatar Oct 24 '21 13:10 yevyevyev

HEY FLUTTER WEB DEVS! After days of toubleshooting I've found the problem, when dealing with meta on a child route, make sure the child route has a path name like /task.

markbulingit avatar Feb 08 '22 02:02 markbulingit

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Aug 16 '22 08:08 github-actions[bot]