router function

  1. @Riverpod(keepAlive: true)
GoRouter router(
  1. dynamic ref
)

A provider for the GoRouter instance.

The GoRouter is used to manage the application's navigation. It is used to navigate to different screens in the application. The routing imlementation uses the go_router package as well as the go_router_builder package, which generates the $appRoutes variable.

The routerListenableProvider is used to listen to changes that should trigger a navigation event. Such triggers are typically authentication changes or cloud notifications that should open a specific screen.

Implementation

@Riverpod(keepAlive: true)
GoRouter router(RouterRef ref) {
  final notifier = ref.watch(routerListenableProvider.notifier);

  return GoRouter(
    navigatorKey: rootNavigatorKey,
    initialLocation: const SplashRoute().location,
    refreshListenable: notifier, // This notifies `GoRouter` for refresh events
    redirect: notifier.redirector, // All the logic is centralized here
    routes: $appRoutes, // All the routes can be found there
  );
}