routes topic
Routes
RouteHref is used to handle navigation behavior.
The routes package has a static registerAuthorizationHandler function which is used to determine what happens when RouteHref.requiresAuth is true and the user is not authenticated. See below for an example implementation, taken from main.dart, where the user is taken to the SignInScreen if AuthorizationService.isAuthorized is false.
Routes.registerAuthorizationHandler(
(_) => AuthorizationService().isAuthorized(),
RouteHref(
builder: (routeEvent) {
NavigationArguments arguments = NavigationArguments();
arguments.removeUntilRoute = LaunchRoutes.home.path;
arguments.routeName =
(routeEvent.settings.arguments as RouteEvent).path;
arguments.authenticationReason.showAdditionalActions = false;
arguments.authenticationReason.description =
routeEvent.authenticationReason ??
AuthenticationLocalizations.of(routeEvent.context!)!
.signInRequiredToProceedLabel;
return wrapWithNavigator(
routeEvent,
(_) => SignInScreen(
navigationArguments: arguments,
),
isLargeFormatLayout(routeEvent.context!),
debugName: "Auth",
navigatorKey: GlobalKey<NavigatorState>(),
popOuterNavigator: true,
);
},
titleBuilder: (_) => 'Sign in | Afrostories',
dialogIf: (routeEvent) => isLargeFormatWeb(routeEvent.context!)));
Classes
- AuthenticationRoutes routes
- Routes defined by the authentication library
- ContentRoutes routes
- Routes defined by the content library
- DonateRoutes routes
- Routes defined by the donate library
- LaunchRoutes routes
- Routes defined by the launch library
- LegalRoutes routes
- Routes defined by the legal library
- UserRoutes routes
- Routes defined by the user library