Reputation: 840
Routes
@MaterialAutoRouter(
routes: <AutoRoute>[
AutoRoute(page: IntroView, initial: true),
AutoRoute(page: LoginView),
AutoRoute(page: MainView, guards: [AuthGuard])),
],
)
class $AppRouter {
IntroView introView;
LoginView loginView;
MainView mainView;
}
The app throws the following error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 'package:k2_flutter/navigation/app_router.gr.dart': Failed assertion: line 24 pos 53: 'authGuard != null': is not true.
In previous versions, this was set in ExtendedNavigator. The documentation is not clear.
class AuthGuard extends AutoRouteGuard {
@override
Future<bool> canNavigate(List<PageRouteInfo> pendingRoutes, StackRouter router) async{
return globalSharedPrefs.getString(PrefHelper.authToken) != null;
}
Upvotes: 0
Views: 1267
Reputation: 31
Widget build(BuildContext context) {
appRouter = AppRouter(authGuard: AuthGuard());//pass it as a argument
}
Upvotes: 1