diff --git a/packages/neon/neon/lib/src/pages/account_settings.dart b/packages/neon/neon/lib/src/pages/account_settings.dart index 11813dbb..0b95a9f6 100644 --- a/packages/neon/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/neon/lib/src/pages/account_settings.dart @@ -28,7 +28,17 @@ class AccountSettingsPage extends StatelessWidget { // ignore: use_build_context_synchronously AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), )) { + final isActive = bloc.activeAccount.value == account; + bloc.removeAccount(account); + + if (isActive) { + // ignore: use_build_context_synchronously + const HomeRoute().go(context); + } else { + // ignore: use_build_context_synchronously + Navigator.of(context).pop(); + } } }, tooltip: AppLocalizations.of(context).accountOptionsRemove, diff --git a/packages/neon/neon/lib/src/pages/login.dart b/packages/neon/neon/lib/src/pages/login.dart index b3ed5c2d..a7715cbf 100644 --- a/packages/neon/neon/lib/src/pages/login.dart +++ b/packages/neon/neon/lib/src/pages/login.dart @@ -84,6 +84,8 @@ class _LoginPageState extends State { ..addAccount(account) ..setActiveAccount(account); } + // ignore: use_build_context_synchronously + const HomeRoute().go(context); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); diff --git a/packages/neon/neon/lib/src/pages/settings.dart b/packages/neon/neon/lib/src/pages/settings.dart index e51b1c33..145d740b 100644 --- a/packages/neon/neon/lib/src/pages/settings.dart +++ b/packages/neon/neon/lib/src/pages/settings.dart @@ -183,7 +183,7 @@ class _SettingsPageState extends State { CustomSettingsTile( title: ElevatedButton.icon( onPressed: () { - const LoginRoute().go(context); + const AddAccountRoute().go(context); }, icon: const Icon(MdiIcons.accountPlus), label: Text(AppLocalizations.of(context).globalOptionsAccountsAdd), diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index d6c397c5..a3ca0b3d 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -1,5 +1,6 @@ // ignore: prefer_mixin -import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; import 'package:neon/neon.dart'; import 'package:provider/provider.dart'; @@ -11,20 +12,18 @@ class AppRouter extends GoRouter { required final GlobalKey navigatorKey, required final AccountsBloc accountsBloc, }) : super( + debugLogDiagnostics: kDebugMode, refreshListenable: StreamListenable.behaviorSubject(accountsBloc.activeAccount), navigatorKey: navigatorKey, initialLocation: const HomeRoute().location, redirect: (final context, final state) { final account = accountsBloc.activeAccount.valueOrNull; + // redirect to loginscreen when no account is logged in if (account == null) { return const LoginRoute().location; } - if (state.location == const LoginRoute().location) { - return const HomeRoute().location; - } - return null; }, routes: $appRoutes, @@ -60,9 +59,13 @@ class AccountSettingsRoute extends GoRouteData { name: 'Settings', routes: [ TypedGoRoute( - path: ':appid', + path: 'apps/:appid', name: 'NextcloudAppSettings', ), + TypedGoRoute( + path: 'account/add', + name: 'addAccount', + ), TypedGoRoute( path: 'account/:accountid', name: 'AccountSettings', @@ -98,6 +101,14 @@ class LoginRoute extends GoRouteData { Widget build(final BuildContext context, final GoRouterState state) => LoginPage(serverURL: server); } +@immutable +class AddAccountRoute extends GoRouteData { + const AddAccountRoute(); + + @override + Widget build(final BuildContext context, final GoRouterState state) => const LoginPage(); +} + @immutable class NextcloudAppSettingsRoute extends GoRouteData { const NextcloudAppSettingsRoute({ @@ -109,7 +120,7 @@ class NextcloudAppSettingsRoute extends GoRouteData { @override Widget build(final BuildContext context, final GoRouterState state) { final appImplementations = Provider.of>(context, listen: false); - final appImplementation = appImplementations.firstWhere((final app) => app.id == appid); + final appImplementation = appImplementations.find(appid)!; return NextcloudAppSettingsPage(appImplementation: appImplementation); } diff --git a/packages/neon/neon/lib/src/router.g.dart b/packages/neon/neon/lib/src/router.g.dart index 406213ea..8a9d98dc 100644 --- a/packages/neon/neon/lib/src/router.g.dart +++ b/packages/neon/neon/lib/src/router.g.dart @@ -22,10 +22,15 @@ RouteBase get $homeRoute => GoRouteData.$route( factory: $SettingsRouteExtension._fromState, routes: [ GoRouteData.$route( - path: ':appid', + path: 'apps/:appid', name: 'NextcloudAppSettings', factory: $NextcloudAppSettingsRouteExtension._fromState, ), + GoRouteData.$route( + path: 'account/add', + name: 'addAccount', + factory: $AddAccountRouteExtension._fromState, + ), GoRouteData.$route( path: 'account/:accountid', name: 'AccountSettings', @@ -70,7 +75,21 @@ extension $NextcloudAppSettingsRouteExtension on NextcloudAppSettingsRoute { ); String get location => GoRouteData.$location( - '/settings/${Uri.encodeComponent(appid)}', + '/settings/apps/${Uri.encodeComponent(appid)}', + ); + + void go(BuildContext context) => context.go(location); + + Future push(BuildContext context) => context.push(location); + + void pushReplacement(BuildContext context) => context.pushReplacement(location); +} + +extension $AddAccountRouteExtension on AddAccountRoute { + static AddAccountRoute _fromState(GoRouterState state) => const AddAccountRoute(); + + String get location => GoRouteData.$location( + '/settings/account/add', ); void go(BuildContext context) => context.go(location);