|
|
@ -25,49 +25,48 @@ import 'package:neon/src/utils/stream_listenable.dart'; |
|
|
|
part 'router.g.dart'; |
|
|
|
part 'router.g.dart'; |
|
|
|
|
|
|
|
|
|
|
|
@internal |
|
|
|
@internal |
|
|
|
class AppRouter extends GoRouter { |
|
|
|
GoRouter buildAppRouter({ |
|
|
|
AppRouter({ |
|
|
|
required final GlobalKey<NavigatorState> navigatorKey, |
|
|
|
required final GlobalKey<NavigatorState> navigatorKey, |
|
|
|
required final AccountsBloc accountsBloc, |
|
|
|
required final AccountsBloc accountsBloc, |
|
|
|
}) => |
|
|
|
}) : super( |
|
|
|
GoRouter( |
|
|
|
debugLogDiagnostics: kDebugMode, |
|
|
|
debugLogDiagnostics: kDebugMode, |
|
|
|
refreshListenable: StreamListenable(accountsBloc.activeAccount), |
|
|
|
refreshListenable: StreamListenable(accountsBloc.activeAccount), |
|
|
|
navigatorKey: navigatorKey, |
|
|
|
navigatorKey: navigatorKey, |
|
|
|
initialLocation: const HomeRoute().location, |
|
|
|
initialLocation: const HomeRoute().location, |
|
|
|
errorPageBuilder: _buildErrorPage, |
|
|
|
errorPageBuilder: _buildErrorPage, |
|
|
|
redirect: (final context, final state) { |
|
|
|
redirect: (final context, final state) { |
|
|
|
final loginQRcode = LoginQRcode.tryParse(state.uri.toString()); |
|
|
|
final loginQRcode = LoginQRcode.tryParse(state.uri.toString()); |
|
|
|
if (loginQRcode != null) { |
|
|
|
if (loginQRcode != null) { |
|
|
|
return LoginCheckServerStatusRoute.withCredentials( |
|
|
|
return LoginCheckServerStatusRoute.withCredentials( |
|
|
|
serverUrl: loginQRcode.serverURL, |
|
|
|
serverUrl: loginQRcode.serverURL, |
|
|
|
loginName: loginQRcode.username, |
|
|
|
loginName: loginQRcode.username, |
|
|
|
password: loginQRcode.password, |
|
|
|
password: loginQRcode.password, |
|
|
|
).location; |
|
|
|
).location; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (accountsBloc.hasAccounts && state.uri.hasScheme) { |
|
|
|
if (accountsBloc.hasAccounts && state.uri.hasScheme) { |
|
|
|
final strippedUri = accountsBloc.activeAccount.value!.stripUri(state.uri); |
|
|
|
final strippedUri = accountsBloc.activeAccount.value!.stripUri(state.uri); |
|
|
|
if (strippedUri != state.uri) { |
|
|
|
if (strippedUri != state.uri) { |
|
|
|
return strippedUri.toString(); |
|
|
|
return strippedUri.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// redirect to login screen when no account is logged in |
|
|
|
// redirect to login screen when no account is logged in |
|
|
|
if (!accountsBloc.hasAccounts && !state.uri.toString().startsWith(const LoginRoute().location)) { |
|
|
|
if (!accountsBloc.hasAccounts && !state.uri.toString().startsWith(const LoginRoute().location)) { |
|
|
|
return const LoginRoute().location; |
|
|
|
return const LoginRoute().location; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
}, |
|
|
|
}, |
|
|
|
routes: $appRoutes, |
|
|
|
routes: $appRoutes, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
static Page<void> _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage( |
|
|
|
Page<void> _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage( |
|
|
|
child: RouteNotFoundPage( |
|
|
|
child: RouteNotFoundPage( |
|
|
|
uri: state.uri, |
|
|
|
uri: state.uri, |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@immutable |
|
|
|
@immutable |
|
|
|
class AccountSettingsRoute extends GoRouteData { |
|
|
|
class AccountSettingsRoute extends GoRouteData { |
|
|
|