From 7b12389316b4c1e08d4fe13c56eefd12467a84fb Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 17 Jun 2023 09:31:16 +0200 Subject: [PATCH] neon: make use of collection in find extensions --- packages/neon/neon/lib/neon.dart | 1 + packages/neon/neon/lib/src/models/account.dart | 11 ++--------- .../neon/neon/lib/src/utils/app_implementation.dart | 10 +--------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index a2093959..8f4ea9ff 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'dart:ui'; import 'package:bitmap/bitmap.dart'; +import 'package:collection/collection.dart'; import 'package:crypto/crypto.dart'; import 'package:file_picker/file_picker.dart'; import 'package:filesize/filesize.dart'; diff --git a/packages/neon/neon/lib/src/models/account.dart b/packages/neon/neon/lib/src/models/account.dart index 999e7710..78bdf0d7 100644 --- a/packages/neon/neon/lib/src/models/account.dart +++ b/packages/neon/neon/lib/src/models/account.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:crypto/crypto.dart'; import 'package:flutter/foundation.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -104,13 +105,5 @@ extension NextcloudClientHelpers on NextcloudClient { } extension AccountFind on Iterable { - Account? find(final String accountID) { - for (final account in this) { - if (account.id == accountID) { - return account; - } - } - - return null; - } + Account? find(final String accountID) => firstWhereOrNull((final account) => account.id == accountID); } diff --git a/packages/neon/neon/lib/src/utils/app_implementation.dart b/packages/neon/neon/lib/src/utils/app_implementation.dart index 9456afb3..9baced14 100644 --- a/packages/neon/neon/lib/src/utils/app_implementation.dart +++ b/packages/neon/neon/lib/src/utils/app_implementation.dart @@ -74,13 +74,5 @@ abstract class AppImplementation { - AppImplementation? find(final String appID) { - for (final app in this) { - if (app.id == appID) { - return app; - } - } - - return null; - } + AppImplementation? find(final String appID) => firstWhereOrNull((final app) => app.id == appID); }