Browse Source

neon: add `AddAccount` route to prevent trying to pop the last page

pull/342/head
Nikolas Rimikis 2 years ago
parent
commit
367f207044
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 12
      packages/neon/neon/lib/src/pages/account_settings.dart
  2. 2
      packages/neon/neon/lib/src/pages/settings.dart
  3. 19
      packages/neon/neon/lib/src/router.dart
  4. 23
      packages/neon/neon/lib/src/router.g.dart

12
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,

2
packages/neon/neon/lib/src/pages/settings.dart

@ -183,7 +183,7 @@ class _SettingsPageState extends State<SettingsPage> {
CustomSettingsTile(
title: ElevatedButton.icon(
onPressed: () {
const LoginRoute().go(context);
const AddAccountRoute().go(context);
},
icon: const Icon(MdiIcons.accountPlus),
label: Text(AppLocalizations.of(context).globalOptionsAccountsAdd),

19
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<NavigatorState> 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<NextcloudAppSettingsRoute>(
path: ':appid',
path: 'apps/:appid',
name: 'NextcloudAppSettings',
),
TypedGoRoute<AddAccountRoute>(
path: 'account/add',
name: 'addAccount',
),
TypedGoRoute<AccountSettingsRoute>(
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({

23
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<T?> push<T>(BuildContext context) => context.push<T>(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);

Loading…
Cancel
Save