auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

AutoRouterDelegate.declarative is deprecated - use guards instead - no docs?

Open realitymolder opened this issue 3 months ago • 8 comments

Hey there, I've tried to use AutoRouterDelegate.declarative on AutoRoute 8, but it seems like it got deprecated. The deprecation message says that I should use guards instead. My goal here is to create an auth routing by AuthState, but I don't want the app to show me the routing animations between pages when the app will route the user after an auth check. How should I convert it into guards? I see no docs on the deprecation message or changelog. P.S due to the fact that I use AutoTabsScaffold I cannot return the HomePage because it has children (is a router of its own).

Code example of the init Widget of the app that should change into guards, apparently.

class HomePage extends HookConsumerWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // Listen to user provider and return relevant screen
    return ref.watch(userControllerProvider).when(
      // Has user - Home screen
      data: (user) {
        // Loading the services in the background
        loadServices(ref, user);
        return userHomePage;
      },
      // Error while loading the user - error screen
      error: (e, s) {
        logger.e('Error Loading Profile $e', stackTrace: s);
        return const ErrorPage();
      },
      // Loading the user - circular loading
      loading: () {
        logger.i('Loading Profile ...');
        return const LoadingPage(shouldload: true);
      },
    );
  }
  }


  /// The home page
  Widget get userHomePage => AutoTabsScaffold(
        extendBody: true,
        backgroundColor: R.colors.white,
        routes: const [
          // MomentsRouter(),
          BrowseRouter(),
          ConnectionsRouter(),
        ],
        resizeToAvoidBottomInset: false,
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: const HomeFloatingActionButton(),
        bottomNavigationBuilder: (context, tabsRouter) =>
            const HomeBottomNavigation(),
      );

Thank you, D.

realitymolder avatar Apr 17 '24 11:04 realitymolder