Skip to content

Commit

Permalink
Merge pull request #988 from nextcloud/renovate/major-go_router
Browse files Browse the repository at this point in the history
fix(deps): update dependency go_router to v12
  • Loading branch information
provokateurin authored Oct 19, 2023
2 parents cd2cb0b + ac6f3ed commit d76e515
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 51 deletions.
4 changes: 2 additions & 2 deletions packages/app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
late final Iterable<AppImplementation> _appImplementations;
late final GlobalOptions _globalOptions;
late final AccountsBloc _accountsBloc;
late final _routerDelegate = AppRouter(
late final _routerDelegate = buildAppRouter(
navigatorKey: _navigatorKey,
accountsBloc: _accountsBloc,
);
Expand Down
85 changes: 42 additions & 43 deletions packages/neon/neon/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigatorState> 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<void> _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage(
child: RouteNotFoundPage(
uri: state.uri,
),
);
}
GoRouter buildAppRouter({
required final GlobalKey<NavigatorState> 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<void> _buildErrorPage(final BuildContext context, final GoRouterState state) => MaterialPage(
child: RouteNotFoundPage(
uri: state.uri,
),
);

@immutable
class AccountSettingsRoute extends GoRouteData {
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_files/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_news/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_notes/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d76e515

Please sign in to comment.