buildConfiguration method
Implementation
GoRouter buildConfiguration(GlobalKey<NavigatorState> key) {
try {
return GoRouter(
navigatorKey: key,
initialLocation: "/splash",
observers: [
...observers,
OpalObserver(),
],
routes: [
...routes.map(_buildRoute),
_buildRoute(const LoginScreen(), topLevel: true),
_buildRoute(const SplashScreen(), topLevel: true)
].map((e) => e.goRoute).toList(),
redirect: (context, state) async {
String uri = state.uri.toString();
bool signedIn = svc<LoginService>().isSignedIn();
bool bound = svc<UserService>().bound;
verbose("Signed In: $signedIn, Bound: $bound, URI: $uri");
if ((!signedIn || !bound) &&
!(uri.startsWith("/splash") || uri.startsWith("/login"))) {
verbose(
"Redirect: $uri -> ${SplashScreen(redirect: uri).toPath()}");
return SplashScreen(redirect: uri).toPath();
}
if (signedIn && uri.startsWith("/login")) {
verbose("Redirect: $uri -> ${const SplashScreen().toPath()}");
return const SplashScreen().toPath();
}
Arcane.opal.setBackgroundSeed(state.uri.toString());
svc<WidgetsBindingService>().dropIfUp();
String? s = await redirect?.call(context, state);
if (s != null) {
verbose("Redirect: $uri -> $s");
}
return s;
},
)..logRouter();
} catch (e, es) {
error(e);
error(es);
}
throw Exception("Failed to build router");
}