From e3c7c8d5f96f8d073c6e498ef4ea2f0feedc6e0e Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 18 Sep 2023 16:06:07 +0200 Subject: [PATCH] feat(neon): add AppImplementation equality Require a Set for runNeon Signed-off-by: Nikolas Rimikis --- packages/app/lib/apps.dart | 4 ++-- packages/neon/neon/lib/neon.dart | 2 +- packages/neon/neon/lib/src/models/app_implementation.dart | 6 ++++++ packages/neon/neon/test/app_implementation_test.dart | 2 ++ .../neon/neon_notifications/lib/neon_notifications.dart | 4 +++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/app/lib/apps.dart b/packages/app/lib/apps.dart index 7fe30719..2ce3f151 100644 --- a/packages/app/lib/apps.dart +++ b/packages/app/lib/apps.dart @@ -4,9 +4,9 @@ import 'package:neon_news/neon_news.dart'; import 'package:neon_notes/neon_notes.dart'; import 'package:neon_notifications/neon_notifications.dart'; -final List appImplementations = [ +final Set appImplementations = { FilesApp(), NewsApp(), NotesApp(), NotificationsApp(), -]; +}; diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index b009b112..b28691c9 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -21,7 +21,7 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; Future runNeon({ - required final Iterable appImplementations, + required final Set appImplementations, required final NeonTheme theme, @visibleForTesting final WidgetsBinding? bindingOverride, @visibleForTesting final Account? account, diff --git a/packages/neon/neon/lib/src/models/app_implementation.dart b/packages/neon/neon/lib/src/models/app_implementation.dart index 25017dd3..75c5d769 100644 --- a/packages/neon/neon/lib/src/models/app_implementation.dart +++ b/packages/neon/neon/lib/src/models/app_implementation.dart @@ -124,6 +124,12 @@ abstract class AppImplementation /// /// You can later access it through `Theme.of(context).extension()`. final ThemeExtension? theme = null; + + @override + bool operator ==(final Object other) => other is AppImplementation && other.id == id; + + @override + int get hashCode => id.hashCode; } extension AppImplementationFind on Iterable { diff --git a/packages/neon/neon/test/app_implementation_test.dart b/packages/neon/neon/test/app_implementation_test.dart index 4747ac76..9564ca68 100644 --- a/packages/neon/neon/test/app_implementation_test.dart +++ b/packages/neon/neon/test/app_implementation_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_implementing_value_types + import 'package:mocktail/mocktail.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:test/test.dart'; diff --git a/packages/neon/neon_notifications/lib/neon_notifications.dart b/packages/neon/neon_notifications/lib/neon_notifications.dart index bd0632a9..18ea3347 100644 --- a/packages/neon/neon_notifications/lib/neon_notifications.dart +++ b/packages/neon/neon_notifications/lib/neon_notifications.dart @@ -21,7 +21,9 @@ part 'options.dart'; part 'pages/main.dart'; class NotificationsApp extends AppImplementation - implements NotificationsAppInterface { + implements + // ignore: avoid_implementing_value_types + NotificationsAppInterface { NotificationsApp(); @override