diff --git a/packages/neon/neon/lib/src/pages/account_settings.dart b/packages/neon/neon/lib/src/pages/account_settings.dart index 29a1057d..0b95a9f6 100644 --- a/packages/neon/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/neon/lib/src/pages/account_settings.dart @@ -28,9 +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); - // ignore: use_build_context_synchronously - const HomeRoute().go(context); + + 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/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 4e9de5eb..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,12 +12,14 @@ 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; } @@ -56,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', @@ -94,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({ 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);