diff --git a/packages/app/pubspec.lock b/packages/app/pubspec.lock index 4bd633d2..75980fe1 100644 --- a/packages/app/pubspec.lock +++ b/packages/app/pubspec.lock @@ -433,10 +433,10 @@ packages: dependency: transitive description: name: go_router - sha256: "2ccd74480706e0a70a0e0dfa9543dede41bc11d0fe3b146a6ad7b7686f6b4407" + sha256: a206cc4621a644531a2e05e7774616ab4d9d85eab1f3b0e255f3102937fccab1 url: "https://pub.dev" source: hosted - version: "11.1.4" + version: "12.0.0" html: dependency: transitive description: diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 2281e150..ce2ce109 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -48,7 +48,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra late final Iterable _appImplementations; late final GlobalOptions _globalOptions; late final AccountsBloc _accountsBloc; - late final _routerDelegate = AppRouter( + late final _routerDelegate = buildAppRouter( navigatorKey: _navigatorKey, accountsBloc: _accountsBloc, ); diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index b1972c9b..83c20b18 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -25,49 +25,48 @@ import 'package:neon/src/utils/stream_listenable.dart'; part 'router.g.dart'; @internal -class AppRouter extends GoRouter { - AppRouter({ - required final GlobalKey navigatorKey, - required final AccountsBloc accountsBloc, - }) : super( - debugLogDiagnostics: kDebugMode, - refreshListenable: StreamListenable(accountsBloc.activeAccount), - navigatorKey: navigatorKey, - initialLocation: const HomeRoute().location, - errorPageBuilder: _buildErrorPage, - redirect: (final context, final state) { - final loginQRcode = LoginQRcode.tryParse(state.uri.toString()); - if (loginQRcode != null) { - return LoginCheckServerStatusRoute.withCredentials( - serverUrl: loginQRcode.serverURL, - loginName: loginQRcode.username, - password: loginQRcode.password, - ).location; - } - - if (accountsBloc.hasAccounts && state.uri.hasScheme) { - final strippedUri = accountsBloc.activeAccount.value!.stripUri(state.uri); - if (strippedUri != state.uri) { - return strippedUri.toString(); - } - } - - // redirect to login screen when no account is logged in - if (!accountsBloc.hasAccounts && !state.uri.toString().startsWith(const LoginRoute().location)) { - return const LoginRoute().location; - } - - return null; - }, - routes: $appRoutes, - ); - - static Page _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage( - child: RouteNotFoundPage( - uri: state.uri, - ), - ); -} +GoRouter buildAppRouter({ + required final GlobalKey navigatorKey, + required final AccountsBloc accountsBloc, +}) => + GoRouter( + debugLogDiagnostics: kDebugMode, + refreshListenable: StreamListenable(accountsBloc.activeAccount), + navigatorKey: navigatorKey, + initialLocation: const HomeRoute().location, + errorPageBuilder: _buildErrorPage, + redirect: (final context, final state) { + final loginQRcode = LoginQRcode.tryParse(state.uri.toString()); + if (loginQRcode != null) { + return LoginCheckServerStatusRoute.withCredentials( + serverUrl: loginQRcode.serverURL, + loginName: loginQRcode.username, + password: loginQRcode.password, + ).location; + } + + if (accountsBloc.hasAccounts && state.uri.hasScheme) { + final strippedUri = accountsBloc.activeAccount.value!.stripUri(state.uri); + if (strippedUri != state.uri) { + return strippedUri.toString(); + } + } + + // redirect to login screen when no account is logged in + if (!accountsBloc.hasAccounts && !state.uri.toString().startsWith(const LoginRoute().location)) { + return const LoginRoute().location; + } + + return null; + }, + routes: $appRoutes, + ); + +Page _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage( + child: RouteNotFoundPage( + uri: state.uri, + ), + ); @immutable class AccountSettingsRoute extends GoRouteData { diff --git a/packages/neon/neon/pubspec.yaml b/packages/neon/neon/pubspec.yaml index 008910e4..b44e8789 100644 --- a/packages/neon/neon/pubspec.yaml +++ b/packages/neon/neon/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: flutter_native_splash: ^2.0.0 flutter_svg: ^2.0.0 flutter_zxing: ^1.0.0 - go_router: ^11.0.0 + go_router: ^12.0.0 http: ^1.0.0 image: ^4.0.0 intersperse: ^2.0.0 diff --git a/packages/neon/neon_files/pubspec.yaml b/packages/neon/neon_files/pubspec.yaml index 0a699722..05974d74 100644 --- a/packages/neon/neon_files/pubspec.yaml +++ b/packages/neon/neon_files/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: flutter_localizations: sdk: flutter flutter_material_design_icons: ^1.0.0 - go_router: ^11.0.0 + go_router: ^12.0.0 image_picker: ^1.0.0 intl: ^0.18.0 neon: diff --git a/packages/neon/neon_news/pubspec.yaml b/packages/neon/neon_news/pubspec.yaml index 3f2aca47..f59d59a0 100644 --- a/packages/neon/neon_news/pubspec.yaml +++ b/packages/neon/neon_news/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: flutter_localizations: sdk: flutter flutter_material_design_icons: ^1.0.0 - go_router: ^11.0.0 + go_router: ^12.0.0 html: ^0.15.0 intl: ^0.18.0 neon: diff --git a/packages/neon/neon_notes/pubspec.yaml b/packages/neon/neon_notes/pubspec.yaml index 5ccf5607..b4caa0c6 100644 --- a/packages/neon/neon_notes/pubspec.yaml +++ b/packages/neon/neon_notes/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: sdk: flutter flutter_markdown: ^0.6.0 flutter_material_design_icons: ^1.0.0 - go_router: ^11.0.0 + go_router: ^12.0.0 intl: ^0.18.0 neon: git: diff --git a/packages/neon/neon_notifications/pubspec.yaml b/packages/neon/neon_notifications/pubspec.yaml index b2c2aeee..8aa3ff5b 100644 --- a/packages/neon/neon_notifications/pubspec.yaml +++ b/packages/neon/neon_notifications/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: flutter_localizations: sdk: flutter flutter_material_design_icons: ^1.0.0 - go_router: ^11.0.0 + go_router: ^12.0.0 intl: ^0.18.0 neon: git: