diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index 7e2692e6..a54428bb 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -109,13 +109,13 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra if (_platform.canUsePushNotifications) { final localNotificationsPlugin = await PushUtils.initLocalNotifications(); Global.onPushNotificationReceived = (final accountID) async { - final account = _accountsBloc.accounts.value.find(accountID); + final account = _accountsBloc.accounts.value.tryFind(accountID); if (account == null) { return; } final allAppImplementations = Provider.of>(context, listen: false); - final app = allAppImplementations.find('notifications') as NotificationsAppInterface?; + final app = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; if (app == null) { return; @@ -124,7 +124,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra await _accountsBloc.getAppsBlocFor(account).getAppBloc(app).refresh(); }; Global.onPushNotificationClicked = (final pushNotificationWithAccountID) async { - final account = _accountsBloc.accounts.value.find(pushNotificationWithAccountID.accountID); + final account = _accountsBloc.accounts.value.tryFind(pushNotificationWithAccountID.accountID); if (account == null) { return; } @@ -132,7 +132,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra final allAppImplementations = Provider.of>(context, listen: false); - final notificationsApp = allAppImplementations.find('notifications') as NotificationsAppInterface?; + final notificationsApp = allAppImplementations.tryFind('notifications') as NotificationsAppInterface?; if (notificationsApp != null) { _accountsBloc .getAppsBlocFor(account) @@ -140,7 +140,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra .deleteNotification(pushNotificationWithAccountID.subject.nid!); } - final app = allAppImplementations.find(pushNotificationWithAccountID.subject.app!) ?? notificationsApp; + final app = allAppImplementations.tryFind(pushNotificationWithAccountID.subject.app) ?? notificationsApp; if (app == null) { return; } diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 614136f2..c130ee00 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -65,7 +65,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState if (_globalOptions.rememberLastUsedAccount.value && _storage.containsKey(_keyLastUsedAccount)) { final lastUsedAccountID = _storage.getString(_keyLastUsedAccount); if (lastUsedAccountID != null) { - final aa = as.find(lastUsedAccountID); + final aa = as.tryFind(lastUsedAccountID); if (aa != null) { setActiveAccount(aa); } @@ -74,7 +74,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState unawaited( _globalOptions.initialAccount.stream.first.then((final lastAccount) { - final account = lastAccount != null ? as.find(lastAccount) : null; + final account = as.tryFind(lastAccount); if (activeAccount.valueOrNull == null) { if (account != null) { setActiveAccount(account); diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 4c77a54a..95312818 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -39,7 +39,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates unawaited( options.initialApp.stream.first.then((var initialApp) async { if (initialApp == null) { - if (result.requireData.find('files') != null) { + if (result.requireData.tryFind('files') != null) { initialApp = 'files'; } else if (result.requireData.isNotEmpty) { // This should never happen, because the files app is always installed and can not be removed, but just in @@ -177,7 +177,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates @override Future setActiveApp(final String? appID) async { if (appID != null && - (await appImplementations.firstWhere((final a) => a.hasData)).requireData.find(appID) != null) { + (await appImplementations.firstWhere((final a) => a.hasData)).requireData.tryFind(appID) != null) { if (activeAppID.valueOrNull != appID) { activeAppID.add(appID); } diff --git a/packages/neon/neon/lib/src/blocs/push_notifications.dart b/packages/neon/neon/lib/src/blocs/push_notifications.dart index 9e37d771..8a2423b5 100644 --- a/packages/neon/neon/lib/src/blocs/push_notifications.dart +++ b/packages/neon/neon/lib/src/blocs/push_notifications.dart @@ -52,7 +52,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, Future _setupUnifiedPush() async { await UnifiedPush.initialize( onNewEndpoint: (final endpoint, final instance) async { - final account = _accountsBloc.accounts.value.find(instance); + final account = _accountsBloc.accounts.value.tryFind(instance); if (account == null) { debugPrint('Account for $instance not found, can not process endpoint'); return; diff --git a/packages/neon/neon/lib/src/models/account.dart b/packages/neon/neon/lib/src/models/account.dart index 78bdf0d7..98741baa 100644 --- a/packages/neon/neon/lib/src/models/account.dart +++ b/packages/neon/neon/lib/src/models/account.dart @@ -105,5 +105,6 @@ extension NextcloudClientHelpers on NextcloudClient { } extension AccountFind on Iterable { - Account? find(final String accountID) => firstWhereOrNull((final account) => account.id == accountID); + Account? tryFind(final String? accountID) => firstWhereOrNull((final account) => account.id == accountID); + Account find(final String accountID) => firstWhere((final account) => account.id == accountID); } diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index 6e48c608..74e648cc 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -126,7 +126,7 @@ class _HomePageState extends State { ] else ...[ if (activeAppIDSnapshot.hasData) ...[ Expanded( - child: appImplementations.data!.find(activeAppIDSnapshot.data!)!.page, + child: appImplementations.data!.find(activeAppIDSnapshot.data!).page, ), ], ], diff --git a/packages/neon/neon/lib/src/pages/login.dart b/packages/neon/neon/lib/src/pages/login.dart index dc7976d6..0b0fd7ed 100644 --- a/packages/neon/neon/lib/src/pages/login.dart +++ b/packages/neon/neon/lib/src/pages/login.dart @@ -74,7 +74,7 @@ class _LoginPageState extends State { if (widget.serverURL != null) { _accountsBloc.updateAccount(account); } else { - final existingAccount = _accountsBloc.accounts.value.find(account.id); + final existingAccount = _accountsBloc.accounts.value.tryFind(account.id); if (existingAccount != null) { NeonException.showSnackbar(context, AppLocalizations.of(context).errorAccountAlreadyExists); await _loginBloc.refresh(); diff --git a/packages/neon/neon/lib/src/router.dart b/packages/neon/neon/lib/src/router.dart index 699f4cad..b37ebb8f 100644 --- a/packages/neon/neon/lib/src/router.dart +++ b/packages/neon/neon/lib/src/router.dart @@ -41,7 +41,7 @@ class AccountSettingsRoute extends GoRouteData { @override Widget build(final BuildContext context, final GoRouterState state) { final bloc = Provider.of(context, listen: false); - final account = bloc.accounts.value.find(accountid)!; + final account = bloc.accounts.value.find(accountid); return AccountSettingsPage( bloc: bloc, @@ -120,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.find(appid)!; + final appImplementation = appImplementations.tryFind(appid)!; return NextcloudAppSettingsPage(appImplementation: appImplementation); } diff --git a/packages/neon/neon/lib/src/utils/app_implementation.dart b/packages/neon/neon/lib/src/utils/app_implementation.dart index 9baced14..8cc14e47 100644 --- a/packages/neon/neon/lib/src/utils/app_implementation.dart +++ b/packages/neon/neon/lib/src/utils/app_implementation.dart @@ -74,5 +74,6 @@ abstract class AppImplementation { - AppImplementation? find(final String appID) => firstWhereOrNull((final app) => app.id == appID); + AppImplementation? tryFind(final String? appID) => firstWhereOrNull((final app) => app.id == appID); + AppImplementation find(final String appID) => firstWhere((final app) => app.id == appID); } diff --git a/packages/neon/neon/lib/src/utils/push_utils.dart b/packages/neon/neon/lib/src/utils/push_utils.dart index d9b9c4b5..04bb9e62 100644 --- a/packages/neon/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/neon/lib/src/utils/push_utils.dart @@ -82,7 +82,7 @@ class PushUtils { AndroidBitmap? largeIconBitmap; try { accounts = loadAccounts(AppStorage('accounts', sharedPreferences)); - account = accounts.find(instance); + account = accounts.tryFind(instance); if (account != null) { notification = (await account.client.notifications.getNotification(id: pushNotification.subject.nid!)).ocs.data; diff --git a/packages/neon/neon/lib/src/utils/settings_export_helper.dart b/packages/neon/neon/lib/src/utils/settings_export_helper.dart index 91059e73..7152dc9c 100644 --- a/packages/neon/neon/lib/src/utils/settings_export_helper.dart +++ b/packages/neon/neon/lib/src/utils/settings_export_helper.dart @@ -20,7 +20,7 @@ class SettingsExportHelper { final appImplementationsData = data['apps'] as Map; for (final appId in appImplementationsData.keys) { - final app = appImplementations.find(appId); + final app = appImplementations.tryFind(appId); if (app == null) { return; } @@ -33,7 +33,7 @@ class SettingsExportHelper { final accountsData = data['accounts'] as Map; for (final accountId in accountsData.keys) { - final account = accountSpecificOptions.keys.find(accountId); + final account = accountSpecificOptions.keys.tryFind(accountId); if (account == null) { return; } diff --git a/packages/neon/neon/lib/src/widgets/app_bar.dart b/packages/neon/neon/lib/src/widgets/app_bar.dart index dddb6d25..2114335e 100644 --- a/packages/neon/neon/lib/src/widgets/app_bar.dart +++ b/packages/neon/neon/lib/src/widgets/app_bar.dart @@ -34,7 +34,7 @@ class NeonAppBar extends StatelessWidget implements PreferredSizeWidget { if (appImplementations.hasData && activeAppIDSnapshot.hasData) ...[ Flexible( child: Text( - appImplementations.requireData.find(activeAppIDSnapshot.data!)!.name(context), + appImplementations.requireData.find(activeAppIDSnapshot.data!).name(context), ), ), ], diff --git a/packages/neon/neon_notifications/lib/pages/main.dart b/packages/neon/neon_notifications/lib/pages/main.dart index bc1a0e00..976acacf 100644 --- a/packages/neon/neon_notifications/lib/pages/main.dart +++ b/packages/neon/neon_notifications/lib/pages/main.dart @@ -51,7 +51,7 @@ class _NotificationsMainPageState extends State { final BuildContext context, final NextcloudNotificationsNotification notification, ) { - final app = Provider.of>(context, listen: false).find(notification.app); + final app = Provider.of>(context, listen: false).tryFind(notification.app); return ListTile( title: Text(notification.subject),