From 060eaf0bafb80b512e982ba7c6ff7daf7ed8e117 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 29 Aug 2023 08:18:29 +0200 Subject: [PATCH] refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): make AppImplementation immutable and cleanup options initialization Signed-off-by: Nikolas Rimikis --- .../neon/lib/src/models/app_implementation.dart | 16 ++++++++-------- .../lib/src/models/notifications_interface.dart | 5 +++++ packages/neon/neon_files/lib/neon_files.dart | 2 +- packages/neon/neon_news/lib/neon_news.dart | 2 +- packages/neon/neon_notes/lib/neon_notes.dart | 2 +- .../lib/neon_notifications.dart | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/neon/neon/lib/src/models/app_implementation.dart b/packages/neon/neon/lib/src/models/app_implementation.dart index 0b5bcafd..4628d10d 100644 --- a/packages/neon/neon/lib/src/models/app_implementation.dart +++ b/packages/neon/neon/lib/src/models/app_implementation.dart @@ -2,6 +2,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:go_router/go_router.dart'; +import 'package:meta/meta.dart'; import 'package:neon/l10n/localizations.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/blocs/accounts.dart'; @@ -12,11 +13,9 @@ import 'package:neon/src/widgets/drawer_destination.dart'; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; +@immutable abstract class AppImplementation { - AppImplementation() { - final storage = AppStorage('app-$id'); - options = buildOptions(storage); - } + AppImplementation(); String get id; LocalizationsDelegate get localizationsDelegate; @@ -25,10 +24,11 @@ abstract class AppImplementation String nameFromLocalization(final AppLocalizations localizations) => localizations.appImplementationName(id); String name(final BuildContext context) => nameFromLocalization(AppLocalizations.of(context)); - late final R options; - @protected - R buildOptions(final AppStorage storage); + late final AppStorage storage = AppStorage('app-$id'); + + @mustBeOverridden + R get options; final Map _blocs = {}; @@ -115,7 +115,7 @@ abstract class AppImplementation /// A custom theme that will be injected into the widget tree. /// /// You can later acess it through `Theme.of(context).extension()`. - ThemeExtension? theme; + final ThemeExtension? theme = null; } extension AppImplementationFind on Iterable { diff --git a/packages/neon/neon/lib/src/models/notifications_interface.dart b/packages/neon/neon/lib/src/models/notifications_interface.dart index b67b3cee..7164dc24 100644 --- a/packages/neon/neon/lib/src/models/notifications_interface.dart +++ b/packages/neon/neon/lib/src/models/notifications_interface.dart @@ -1,3 +1,4 @@ +import 'package:meta/meta.dart'; import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/settings/models/nextcloud_app_options.dart'; @@ -5,6 +6,10 @@ import 'package:neon/src/settings/models/nextcloud_app_options.dart'; abstract interface class NotificationsAppInterface extends AppImplementation { NotificationsAppInterface(); + + @override + @mustBeOverridden + R get options => throw UnimplementedError(); } abstract interface class NotificationsBlocInterface extends InteractiveBloc { diff --git a/packages/neon/neon_files/lib/neon_files.dart b/packages/neon/neon_files/lib/neon_files.dart index b7c48b13..724f058b 100644 --- a/packages/neon/neon_files/lib/neon_files.dart +++ b/packages/neon/neon_files/lib/neon_files.dart @@ -56,7 +56,7 @@ class FilesApp extends AppImplementation { List supportedLocales = AppLocalizations.supportedLocales; @override - FilesAppSpecificOptions buildOptions(final AppStorage storage) => FilesAppSpecificOptions(storage); + late final FilesAppSpecificOptions options = FilesAppSpecificOptions(storage); @override FilesBloc buildBloc(final Account account) => FilesBloc( diff --git a/packages/neon/neon_news/lib/neon_news.dart b/packages/neon/neon_news/lib/neon_news.dart index acb4ad08..c6cf5125 100644 --- a/packages/neon/neon_news/lib/neon_news.dart +++ b/packages/neon/neon_news/lib/neon_news.dart @@ -64,7 +64,7 @@ class NewsApp extends AppImplementation { List supportedLocales = AppLocalizations.supportedLocales; @override - NewsAppSpecificOptions buildOptions(final AppStorage storage) => NewsAppSpecificOptions(storage); + late final NewsAppSpecificOptions options = NewsAppSpecificOptions(storage); @override NewsBloc buildBloc(final Account account) => NewsBloc( diff --git a/packages/neon/neon_notes/lib/neon_notes.dart b/packages/neon/neon_notes/lib/neon_notes.dart index af8fbb94..96040a89 100644 --- a/packages/neon/neon_notes/lib/neon_notes.dart +++ b/packages/neon/neon_notes/lib/neon_notes.dart @@ -54,7 +54,7 @@ class NotesApp extends AppImplementation { LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; @override - NotesAppSpecificOptions buildOptions(final AppStorage storage) => NotesAppSpecificOptions(storage); + late final NotesAppSpecificOptions options = NotesAppSpecificOptions(storage); @override NotesBloc buildBloc(final Account account) => NotesBloc( diff --git a/packages/neon/neon_notifications/lib/neon_notifications.dart b/packages/neon/neon_notifications/lib/neon_notifications.dart index 902dd7b4..9da97fca 100644 --- a/packages/neon/neon_notifications/lib/neon_notifications.dart +++ b/packages/neon/neon_notifications/lib/neon_notifications.dart @@ -34,7 +34,7 @@ class NotificationsApp extends AppImplementation supportedLocales = AppLocalizations.supportedLocales; @override - NotificationsAppSpecificOptions buildOptions(final AppStorage storage) => NotificationsAppSpecificOptions(storage); + late final NotificationsAppSpecificOptions options = NotificationsAppSpecificOptions(storage); @override NotificationsBloc buildBloc(final Account account) => NotificationsBloc(