Skip to content

High performance self-hosted photo and video management solution.

refactor(mobile): Use `switch` expression when possible (#15852)

Damiano Ferrari96a6cc20b7f1
diff --git a/mobile/lib/entities/asset.entity.dart b/mobile/lib/entities/asset.entity.dart
index 4bec35970a..f6b10a3ab5 100644
--- a/mobile/lib/entities/asset.entity.dart
+++ b/mobile/lib/entities/asset.entity.dart
@@ -545,19 +545,13 @@ enum AssetType {
}
extension AssetTypeEnumHelper on AssetTypeEnum {
- AssetType toAssetType() {
- switch (this) {
- case AssetTypeEnum.IMAGE:
- return AssetType.image;
- case AssetTypeEnum.VIDEO:
- return AssetType.video;
- case AssetTypeEnum.AUDIO:
- return AssetType.audio;
- case AssetTypeEnum.OTHER:
- return AssetType.other;
- }
- throw Exception();
- }
+ AssetType toAssetType() => switch (this) {
+ AssetTypeEnum.IMAGE => AssetType.image,
+ AssetTypeEnum.VIDEO => AssetType.video,
+ AssetTypeEnum.AUDIO => AssetType.audio,
+ AssetTypeEnum.OTHER => AssetType.other,
+ _ => throw Exception(),
+ };
}
/// Describes where the information of this asset came from:
diff --git a/mobile/lib/entities/store.entity.dart b/mobile/lib/entities/store.entity.dart
index a7f2db78d0..a6ebe77c4f 100644
--- a/mobile/lib/entities/store.entity.dart
+++ b/mobile/lib/entities/store.entity.dart
@@ -96,25 +96,16 @@ class StoreValue {
int? intValue;
String? strValue;
- T? _extract<T>(StoreKey<T> key) {
- switch (key.type) {
- case const (int):
- return intValue as T?;
- case const (bool):
- return intValue == null ? null : (intValue! == 1) as T;
- case const (DateTime):
- return intValue == null
+ T? _extract<T>(StoreKey<T> key) => switch (key.type) {
+ const (int) => intValue as T?,
+ const (bool) => intValue == null ? null : (intValue! == 1) as T,
+ const (DateTime) => intValue == null
? null
- : DateTime.fromMicrosecondsSinceEpoch(intValue!) as T;
- case const (String):
- return strValue as T?;
- default:
- if (key.fromDb != null) {
- return key.fromDb!.call(Store._db, intValue!);
- }
- }
- throw TypeError();
- }
+ : DateTime.fromMicrosecondsSinceEpoch(intValue!) as T,
+ const (String) => strValue as T?,
+ _ when key.fromDb != null => key.fromDb!.call(Store._db, intValue!),
+ _ => throw TypeError(),
+ };
static Future<StoreValue> _of<T>(T? value, StoreKey<T> key) async {
int? i;
diff --git a/mobile/lib/entities/user.entity.dart b/mobile/lib/entities/user.entity.dart
index 55a19fe496..8fa6e83874 100644
--- a/mobile/lib/entities/user.entity.dart
+++ b/mobile/lib/entities/user.entity.dart
@@ -149,56 +149,33 @@ enum AvatarColorEnum {
}
extension AvatarColorEnumHelper on UserAvatarColor {
- AvatarColorEnum toAvatarColor() {
- switch (this) {
- case UserAvatarColor.primary:
- return AvatarColorEnum.primary;
- case UserAvatarColor.pink:
- return AvatarColorEnum.pink;
- case UserAvatarColor.red:
- return AvatarColorEnum.red;
- case UserAvatarColor.yellow:
- return AvatarColorEnum.yellow;
- case UserAvatarColor.blue:
- return AvatarColorEnum.blue;
- case UserAvatarColor.green:
- return AvatarColorEnum.green;
- case UserAvatarColor.purple:
- return AvatarColorEnum.purple;
- case UserAvatarColor.orange:
- return AvatarColorEnum.orange;
- case UserAvatarColor.gray:
- return AvatarColorEnum.gray;
- case UserAvatarColor.amber:
- return AvatarColorEnum.amber;
- }
- return AvatarColorEnum.primary;
- }
+ AvatarColorEnum toAvatarColor() => switch (this) {
+ UserAvatarColor.primary => AvatarColorEnum.primary,
+ UserAvatarColor.pink => AvatarColorEnum.pink,
+ UserAvatarColor.red => AvatarColorEnum.red,
+ UserAvatarColor.yellow => AvatarColorEnum.yellow,
+ UserAvatarColor.blue => AvatarColorEnum.blue,
+ UserAvatarColor.green => AvatarColorEnum.green,
+ UserAvatarColor.purple => AvatarColorEnum.purple,
+ UserAvatarColor.orange => AvatarColorEnum.orange,
+ UserAvatarColor.gray => AvatarColorEnum.gray,
+ UserAvatarColor.amber => AvatarColorEnum.amber,
+ _ => AvatarColorEnum.primary,
+ };
}
extension AvatarColorToColorHelper on AvatarColorEnum {
- Color toColor([bool isDarkTheme = false]) {
- switch (this) {
- case AvatarColorEnum.primary:
- return isDarkTheme ? const Color(0xFFABCBFA) : const Color(0xFF4250AF);
- case AvatarColorEnum.pink:
- return const Color.fromARGB(255, 244, 114, 182);
- case AvatarColorEnum.red:
- return const Color.fromARGB(255, 239, 68, 68);
- case AvatarColorEnum.yellow:
- return const Color.fromARGB(255, 234, 179, 8);
- case AvatarColorEnum.blue:
- return const Color.fromARGB(255, 59, 130, 246);
- case AvatarColorEnum.green:
- return const Color.fromARGB(255, 22, 163, 74);
- case AvatarColorEnum.purple:
- return const Color.fromARGB(255, 147, 51, 234);
- case AvatarColorEnum.orange:
- return const Color.fromARGB(255, 234, 88, 12);
- case AvatarColorEnum.gray:
- return const Color.fromARGB(255, 75, 85, 99);
- case AvatarColorEnum.amber:
- return const Color.fromARGB(255, 217, 119, 6);
- }
- }
+ Color toColor([bool isDarkTheme = false]) => switch (this) {
+ AvatarColorEnum.primary =>
+ isDarkTheme ? const Color(0xFFABCBFA) : const Color(0xFF4250AF),
+ AvatarColorEnum.pink => const Color.fromARGB(255, 244, 114, 182),
+ AvatarColorEnum.red => const Color.fromARGB(255, 239, 68, 68),
+ AvatarColorEnum.yellow => const Color.fromARGB(255, 234, 179, 8),
+ AvatarColorEnum.blue => const Color.fromARGB(255, 59, 130, 246),
+ AvatarColorEnum.green => const Color.fromARGB(255, 22, 163, 74),
+ AvatarColorEnum.purple => const Color.fromARGB(255, 147, 51, 234),
+ AvatarColorEnum.orange => const Color.fromARGB(255, 234, 88, 12),
+ AvatarColorEnum.gray => const Color.fromARGB(255, 75, 85, 99),
+ AvatarColorEnum.amber => const Color.fromARGB(255, 217, 119, 6),
+ };
}
diff --git a/mobile/lib/pages/common/app_log.page.dart b/mobile/lib/pages/common/app_log.page.dart
index fd718ee37d..226d380a28 100644
--- a/mobile/lib/pages/common/app_log.page.dart
+++ b/mobile/lib/pages/common/app_log.page.dart
@@ -36,32 +36,19 @@ class AppLogPage extends HookConsumerWidget {
);
}
- Widget buildLeadingIcon(LogLevel level) {
- switch (level) {
- case LogLevel.INFO:
- return colorStatusIndicator(context.primaryColor);
- case LogLevel.SEVERE:
- return colorStatusIndicator(Colors.redAccent);
+ Widget buildLeadingIcon(LogLevel level) => switch (level) {
+ LogLevel.INFO => colorStatusIndicator(context.primaryColor),
+ LogLevel.SEVERE => colorStatusIndicator(Colors.redAccent),
+ LogLevel.WARNING => colorStatusIndicator(Colors.orangeAccent),
+ _ => colorStatusIndicator(Colors.grey),
+ };
- case LogLevel.WARNING:
- return colorStatusIndicator(Colors.orangeAccent);
- default:
- return colorStatusIndicator(Colors.grey);
- }
- }
-
- getTileColor(LogLevel level) {
- switch (level) {
- case LogLevel.INFO:
- return Colors.transparent;
- case LogLevel.SEVERE:
- return Colors.redAccent.withOpacity(0.25);
- case LogLevel.WARNING:
- return Colors.orangeAccent.withOpacity(0.25);
- default:
- return context.primaryColor.withOpacity(0.1);
- }
- }
+ Color getTileColor(LogLevel level) => switch (level) {
+ LogLevel.INFO => Colors.transparent,
+ LogLevel.SEVERE => Colors.redAccent.withOpacity(0.25),
+ LogLevel.WARNING => Colors.orangeAccent.withOpacity(0.25),
+ _ => context.primaryColor.withOpacity(0.1),
+ };
return Scaffold(
appBar: AppBar(
diff --git a/mobile/lib/pages/common/download_panel.dart b/mobile/lib/pages/common/download_panel.dart
index 4421e337e9..5cc6e5b8d6 100644
--- a/mobile/lib/pages/common/download_panel.dart
+++ b/mobile/lib/pages/common/download_panel.dart
@@ -74,26 +74,16 @@ class DownloadTaskTile extends StatelessWidget {
Widget build(BuildContext context) {
final progressPercent = (progress * 100).round();
- getStatusText() {
- switch (status) {
- case TaskStatus.running:
- return 'downloading'.tr();
- case TaskStatus.complete:
- return 'download_complete'.tr();
- case TaskStatus.failed:
- return 'download_failed'.tr();
- case TaskStatus.canceled:
- return 'download_canceled'.tr();
- case TaskStatus.paused:
- return 'download_paused'.tr();
- case TaskStatus.enqueued:
- return 'download_enqueue'.tr();
- case TaskStatus.notFound:
- return 'download_notfound'.tr();
- case TaskStatus.waitingToRetry:
- return 'download_waiting_to_retry'.tr();
- }
- }
+ String getStatusText() => switch (status) {
+ TaskStatus.running => 'downloading'.tr(),
+ TaskStatus.complete => 'download_complete'.tr(),
+ TaskStatus.failed => 'download_failed'.tr(),
+ TaskStatus.canceled => 'download_canceled'.tr(),
+ TaskStatus.paused => 'download_paused'.tr(),
+ TaskStatus.enqueued => 'download_enqueue'.tr(),
+ TaskStatus.notFound => 'download_notfound'.tr(),
+ TaskStatus.waitingToRetry => 'download_waiting_to_retry'.tr(),
+ };
return SizedBox(
key: const ValueKey('download_progress'),
diff --git a/mobile/lib/pages/editing/crop.page.dart b/mobile/lib/pages/editing/crop.page.dart
index dc467f5740..f7f459c770 100644
--- a/mobile/lib/pages/editing/crop.page.dart
+++ b/mobile/lib/pages/editing/crop.page.dart
@@ -174,33 +174,19 @@ class _AspectRatioButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
- IconData iconData;
- switch (label) {
- case 'Free':
- iconData = Icons.crop_free_rounded;
- break;
- case '1:1':
- iconData = Icons.crop_square_rounded;
- break;
- case '16:9':
- iconData = Icons.crop_16_9_rounded;
- break;
- case '3:2':
- iconData = Icons.crop_3_2_rounded;
- break;
- case '7:5':
- iconData = Icons.crop_7_5_rounded;
- break;
- default:
- iconData = Icons.crop_free_rounded;
- }
-
return Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: Icon(
- iconData,
+ switch (label) {
+ 'Free' => Icons.crop_free_rounded,
+ '1:1' => Icons.crop_square_rounded,
+ '16:9' => Icons.crop_16_9_rounded,
+ '3:2' => Icons.crop_3_2_rounded,
+ '7:5' => Icons.crop_7_5_rounded,
+ _ => Icons.crop_free_rounded,
+ },
color: aspectRatio.value == ratio
? context.primaryColor
: context.themeData.iconTheme.color,
diff --git a/mobile/lib/pages/onboarding/permission_onboarding.page.dart b/mobile/lib/pages/onboarding/permission_onboarding.page.dart
index e5408f2297..dc9923303b 100644
--- a/mobile/lib/pages/onboarding/permission_onboarding.page.dart
+++ b/mobile/lib/pages/onboarding/permission_onboarding.page.dart
@@ -136,23 +136,16 @@ class PermissionOnboardingPage extends HookConsumerWidget {
);
}
- final Widget child;
- switch (permission) {
- case PermissionStatus.limited:
- child = buildPermissionLimited();
- break;
- case PermissionStatus.denied:
- child = buildRequestPermission();
- break;
- case PermissionStatus.granted:
- case PermissionStatus.provisional:
- child = buildPermissionGranted();
- break;
- case PermissionStatus.restricted:
- case PermissionStatus.permanentlyDenied:
- child = buildPermissionDenied();
- break;
- }
+ final Widget child = switch (permission) {
+ PermissionStatus.limited => buildPermissionLimited(),
+ PermissionStatus.denied => buildRequestPermission(),
+ PermissionStatus.granted ||
+ PermissionStatus.provisional =>
+ buildPermissionGranted(),
+ PermissionStatus.restricted ||
+ PermissionStatus.permanentlyDenied =>
+ buildPermissionDenied()
+ };
return Scaffold(
body: SafeArea(
diff --git a/mobile/lib/repositories/album.repository.dart b/mobile/lib/repositories/album.repository.dart
index adf83b33d4..7f4beee3bb 100644
--- a/mobile/lib/repositories/album.repository.dart
+++ b/mobile/lib/repositories/album.repository.dart
@@ -18,15 +18,11 @@ class AlbumRepository extends DatabaseRepository implements IAlbumRepository {
@override
Future<int> count({bool? local}) {
final baseQuery = db.albums.where();
- final QueryBuilder<Album, Album, QAfterWhereClause> query;
- switch (local) {
- case null:
- query = baseQuery.noOp();
- case true:
- query = baseQuery.localIdIsNotNull();
- case false:
- query = baseQuery.remoteIdIsNotNull();
- }
+ final QueryBuilder<Album, Album, QAfterWhereClause> query = switch (local) {
+ null => baseQuery.noOp(),
+ true => baseQuery.localIdIsNotNull(),
+ false => baseQuery.remoteIdIsNotNull(),
+ };
return query.count();
}
@@ -91,15 +87,11 @@ class AlbumRepository extends DatabaseRepository implements IAlbumRepository {
if (ownerId != null) {
filterQuery = filterQuery.owner((q) => q.isarIdEqualTo(ownerId));
}
- final QueryBuilder<Album, Album, QAfterSortBy> query;
- switch (sortBy) {
- case null:
- query = filterQuery.noOp();
- case AlbumSort.remoteId:
- query = filterQuery.sortByRemoteId();
- case AlbumSort.localId:
- query = filterQuery.sortByLocalId();
- }
+ final QueryBuilder<Album, Album, QAfterSortBy> query = switch (sortBy) {
+ null => filterQuery.noOp(),
+ AlbumSort.remoteId => filterQuery.sortByRemoteId(),
+ AlbumSort.localId => filterQuery.sortByLocalId(),
+ };
return query.findAll();
}
@@ -150,14 +142,11 @@ class AlbumRepository extends DatabaseRepository implements IAlbumRepository {
query = query.owner(
(q) => q.not().isarIdEqualTo(Store.get(StoreKey.currentUser).isarId),
);
- break;
case QuickFilterMode.myAlbums:
query = query.owner(
(q) => q.isarIdEqualTo(Store.get(StoreKey.currentUser).isarId),
);
- break;
case QuickFilterMode.all:
- default:
break;
}
diff --git a/mobile/lib/repositories/asset.repository.dart b/mobile/lib/repositories/asset.repository.dart
index eaaafd3045..36e976a1ab 100644
--- a/mobile/lib/repositories/asset.repository.dart
+++ b/mobile/lib/repositories/asset.repository.dart
@@ -38,27 +38,20 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
query = query.ownerIdEqualTo(ownerId);
}
- switch (state) {
- case null:
- break;
- case AssetState.local:
- query = query.remoteIdIsNull();
- case AssetState.remote:
- query = query.localIdIsNull();
- case AssetState.merged:
- query = query.localIdIsNotNull().remoteIdIsNotNull();
+ if (state != null) {
+ query = switch (state) {
+ AssetState.local => query.remoteIdIsNull(),
+ AssetState.remote => query.localIdIsNull(),
+ AssetState.merged => query.localIdIsNotNull().remoteIdIsNotNull(),
+ };
}
- final QueryBuilder<Asset, Asset, QAfterSortBy> sortedQuery;
-
- switch (sortBy) {
- case null:
- sortedQuery = query.noOp();
- case AssetSort.checksum:
- sortedQuery = query.sortByChecksum();
- case AssetSort.ownerIdChecksum:
- sortedQuery = query.sortByOwnerId().thenByChecksum();
- }
+ final QueryBuilder<Asset, Asset, QAfterSortBy> sortedQuery =
+ switch (sortBy) {
+ null => query.noOp(),
+ AssetSort.checksum => query.sortByChecksum(),
+ AssetSort.ownerIdChecksum => query.sortByOwnerId().thenByChecksum(),
+ };
return sortedQuery.findAll();
}
@@ -84,16 +77,12 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
AssetState? state,
) {
final query = db.assets.remote(ids).filter();
- switch (state) {
- case null:
- return query.noOp();
- case AssetState.local:
- return query.remoteIdIsNull();
- case AssetState.remote:
- return query.localIdIsNull();
- case AssetState.merged:
- return query.localIdIsNotEmpty().remoteIdIsNotNull();
- }
+ return switch (state) {
+ null => query.noOp(),
+ AssetState.local => query.remoteIdIsNull(),
+ AssetState.remote => query.localIdIsNull(),
+ AssetState.merged => query.localIdIsNotEmpty().remoteIdIsNotNull(),
+ };
}
@override
@@ -104,39 +93,32 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
int? limit,
}) {
final baseQuery = db.assets.where();
- final QueryBuilder<Asset, Asset, QAfterFilterCondition> filteredQuery;
- switch (state) {
- case null:
- filteredQuery = baseQuery.ownerIdEqualToAnyChecksum(ownerId).noOp();
- case AssetState.local:
- filteredQuery = baseQuery
- .remoteIdIsNull()
- .filter()
- .localIdIsNotNull()
- .ownerIdEqualTo(ownerId);
- case AssetState.remote:
- filteredQuery = baseQuery
- .localIdIsNull()
- .filter()
- .remoteIdIsNotNull()
- .ownerIdEqualTo(ownerId);
- case AssetState.merged:
- filteredQuery = baseQuery
- .ownerIdEqualToAnyChecksum(ownerId)
- .filter()
- .remoteIdIsNotNull()
- .localIdIsNotNull();
- }
-
- final QueryBuilder<Asset, Asset, QAfterSortBy> query;
- switch (sortBy) {
- case null:
- query = filteredQuery.noOp();
- case AssetSort.checksum:
- query = filteredQuery.sortByChecksum();
- case AssetSort.ownerIdChecksum:
- query = filteredQuery.sortByOwnerId().thenByChecksum();
- }
+ final QueryBuilder<Asset, Asset, QAfterFilterCondition> filteredQuery =
+ switch (state) {
+ null => baseQuery.ownerIdEqualToAnyChecksum(ownerId).noOp(),
+ AssetState.local => baseQuery
+ .remoteIdIsNull()
+ .filter()
+ .localIdIsNotNull()
+ .ownerIdEqualTo(ownerId),
+ AssetState.remote => baseQuery
+ .localIdIsNull()
+ .filter()
+ .remoteIdIsNotNull()
+ .ownerIdEqualTo(ownerId),
+ AssetState.merged => baseQuery
+ .ownerIdEqualToAnyChecksum(ownerId)
+ .filter()
+ .remoteIdIsNotNull()
+ .localIdIsNotNull(),
+ };
+
+ final QueryBuilder<Asset, Asset, QAfterSortBy> query = switch (sortBy) {
+ null => filteredQuery.noOp(),
+ AssetSort.checksum => filteredQuery.sortByChecksum(),
+ AssetSort.ownerIdChecksum =>
+ filteredQuery.sortByOwnerId().thenByChecksum(),
+ };
return limit == null ? query.findAll() : query.limit(limit).findAll();
}
@@ -155,17 +137,16 @@ class AssetRepository extends DatabaseRepository implements IAssetRepository {
int limit = 100,
}) {
final baseQuery = db.assets.where();
- final QueryBuilder<Asset, Asset, QAfterFilterCondition> query;
- switch (state) {
- case null:
- query = baseQuery.noOp();
- case AssetState.local:
- query = baseQuery.remoteIdIsNull().filter().localIdIsNotNull();
- case AssetState.remote:
- query = baseQuery.localIdIsNull().filter().remoteIdIsNotNull();
- case AssetState.merged:
- query = baseQuery.localIdIsNotNull().filter().remoteIdIsNotNull();
- }
+ final QueryBuilder<Asset, Asset, QAfterFilterCondition> query =
+ switch (state) {
+ null => baseQuery.noOp(),
+ AssetState.local =>
+ baseQuery.remoteIdIsNull().filter().localIdIsNotNull(),
+ AssetState.remote =>
+ baseQuery.localIdIsNull().filter().remoteIdIsNotNull(),
+ AssetState.merged =>
+ baseQuery.localIdIsNotNull().filter().remoteIdIsNotNull(),
+ };
return _getMatchesImpl(query, ownerId, assets, limit);
}
diff --git a/mobile/lib/repositories/backup.repository.dart b/mobile/lib/repositories/backup.repository.dart
index 61997ff23a..ed3a9c27e4 100644
--- a/mobile/lib/repositories/backup.repository.dart
+++ b/mobile/lib/repositories/backup.repository.dart
@@ -14,13 +14,11 @@ class BackupRepository extends DatabaseRepository implements IBackupRepository {
@override
Future<List<BackupAlbum>> getAll({BackupAlbumSort? sort}) {
final baseQuery = db.backupAlbums.where();
- final QueryBuilder<BackupAlbum, BackupAlbum, QAfterSortBy> query;
- switch (sort) {
- case null:
- query = baseQuery.noOp();
- case BackupAlbumSort.id:
- query = baseQuery.sortById();
- }
+ final QueryBuilder<BackupAlbum, BackupAlbum, QAfterSortBy> query =
+ switch (sort) {
+ null => baseQuery.noOp(),
+ BackupAlbumSort.id => baseQuery.sortById(),
+ };
return query.findAll();
}
diff --git a/mobile/lib/repositories/user.repository.dart b/mobile/lib/repositories/user.repository.dart
index fb4df84fe7..bc9325c9e9 100644
--- a/mobile/lib/repositories/user.repository.dart
+++ b/mobile/lib/repositories/user.repository.dart
@@ -25,13 +25,10 @@ class UserRepository extends DatabaseRepository implements IUserRepository {
final int userId = Store.get(StoreKey.currentUser).isarId;
final QueryBuilder<User, User, QAfterWhereClause> afterWhere =
self ? baseQuery.noOp() : baseQuery.isarIdNotEqualTo(userId);
- final QueryBuilder<User, User, QAfterSortBy> query;
- switch (sortBy) {
- case null:
- query = afterWhere.noOp();
- case UserSort.id:
- query = afterWhere.sortById();
- }
+ final QueryBuilder<User, User, QAfterSortBy> query = switch (sortBy) {
+ null => afterWhere.noOp(),
+ UserSort.id => afterWhere.sortById(),
+ };
return query.findAll();
}
diff --git a/mobile/lib/services/backup.service.dart b/mobile/lib/services/backup.service.dart
index 7bce1047e2..802a98571e 100644
--- a/mobile/lib/services/backup.service.dart
+++ b/mobile/lib/services/backup.service.dart
@@ -519,18 +519,12 @@ class BackupService {
return responseBody.containsKey('id') ? responseBody['id'] : null;
}
- String _getAssetType(AssetType assetType) {
- switch (assetType) {
- case AssetType.audio:
- return "AUDIO";
- case AssetType.image:
- return "IMAGE";
- case AssetType.video:
- return "VIDEO";
- case AssetType.other:
- return "OTHER";
- }
- }
+ String _getAssetType(AssetType assetType) => switch (assetType) {
+ AssetType.audio => "AUDIO",
+ AssetType.image => "IMAGE",
+ AssetType.video => "VIDEO",
+ AssetType.other => "OTHER",
+ };
}
class MultipartRequest extends http.MultipartRequest {
diff --git a/mobile/lib/utils/storage_indicator.dart b/mobile/lib/utils/storage_indicator.dart
index 4764c45385..a7dad063ca 100644
--- a/mobile/lib/utils/storage_indicator.dart
+++ b/mobile/lib/utils/storage_indicator.dart
@@ -2,13 +2,8 @@ import 'package:flutter/material.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
/// Returns the suitable [IconData] to represent an [Asset]s storage location
-IconData storageIcon(Asset asset) {
- switch (asset.storage) {
- case AssetState.local:
- return Icons.cloud_off_outlined;
- case AssetState.remote:
- return Icons.cloud_outlined;
- case AssetState.merged:
- return Icons.cloud_done_outlined;
- }
-}
+IconData storageIcon(Asset asset) => switch (asset.storage) {
+ AssetState.local => Icons.cloud_off_outlined,
+ AssetState.remote => Icons.cloud_outlined,
+ AssetState.merged => Icons.cloud_done_outlined,
+ };
diff --git a/mobile/lib/widgets/common/immich_toast.dart b/mobile/lib/widgets/common/immich_toast.dart
index d33f6c4caf..b0f1306aba 100644
--- a/mobile/lib/widgets/common/immich_toast.dart
+++ b/mobile/lib/widgets/common/immich_toast.dart
@@ -15,36 +15,26 @@ class ImmichToast {
final fToast = FToast();
fToast.init(context);
- Color getColor(ToastType type, BuildContext context) {
- switch (type) {
- case ToastType.info:
- return context.primaryColor;
- case ToastType.success:
- return const Color.fromARGB(255, 78, 140, 124);
- case ToastType.error:
- return const Color.fromARGB(255, 220, 48, 85);
- }
- }
+ Color getColor(ToastType type, BuildContext context) => switch (type) {
+ ToastType.info => context.primaryColor,
+ ToastType.success => const Color.fromARGB(255, 78, 140, 124),
+ ToastType.error => const Color.fromARGB(255, 220, 48, 85),
+ };
- Icon getIcon(ToastType type) {
- switch (type) {
- case ToastType.info:
- return Icon(
- Icons.info_outline_rounded,
- color: context.primaryColor,
- );
- case ToastType.success:
- return const Icon(
- Icons.check_circle_rounded,
- color: Color.fromARGB(255, 78, 140, 124),
- );
- case ToastType.error:
- return const Icon(
- Icons.error_outline_rounded,
- color: Color.fromARGB(255, 240, 162, 156),
- );
- }
- }
+ Icon getIcon(ToastType type) => switch (type) {
+ ToastType.info => Icon(
+ Icons.info_outline_rounded,
+ color: context.primaryColor,
+ ),
+ ToastType.success => const Icon(
+ Icons.check_circle_rounded,
+ color: Color.fromARGB(255, 78, 140, 124),
+ ),
+ ToastType.error => const Icon(
+ Icons.error_outline_rounded,
+ color: Color.fromARGB(255, 240, 162, 156),
+ ),
+ };
fToast.showToast(
child: Container(
diff --git a/mobile/lib/widgets/photo_view/photo_view.dart b/mobile/lib/widgets/photo_view/photo_view.dart
index 7f72750afe..f72d1e298f 100644
--- a/mobile/lib/widgets/photo_view/photo_view.dart
+++ b/mobile/lib/widgets/photo_view/photo_view.dart
@@ -590,21 +590,15 @@ class _PhotoViewState extends State<PhotoView>
}
/// The default [ScaleStateCycle]
-PhotoViewScaleState defaultScaleStateCycle(PhotoViewScaleState actual) {
- switch (actual) {
- case PhotoViewScaleState.initial:
- return PhotoViewScaleState.covering;
- case PhotoViewScaleState.covering:
- return PhotoViewScaleState.originalSize;
- case PhotoViewScaleState.originalSize:
- return PhotoViewScaleState.initial;
- case PhotoViewScaleState.zoomedIn:
- case PhotoViewScaleState.zoomedOut:
- return PhotoViewScaleState.initial;
- default:
- return PhotoViewScaleState.initial;
- }
-}
+PhotoViewScaleState defaultScaleStateCycle(PhotoViewScaleState actual) =>
+ switch (actual) {
+ PhotoViewScaleState.initial => PhotoViewScaleState.covering,
+ PhotoViewScaleState.covering => PhotoViewScaleState.originalSize,
+ PhotoViewScaleState.originalSize => PhotoViewScaleState.initial,
+ PhotoViewScaleState.zoomedIn ||
+ PhotoViewScaleState.zoomedOut =>
+ PhotoViewScaleState.initial,
+ };
/// A type definition for a [Function] that receives the actual [PhotoViewScaleState] and returns the next one
/// It is used internally to walk in the "doubletap gesture cycle".
diff --git a/mobile/lib/widgets/photo_view/src/utils/photo_view_utils.dart b/mobile/lib/widgets/photo_view/src/utils/photo_view_utils.dart
index d91e9f51dd..9c632df3bf 100644
--- a/mobile/lib/widgets/photo_view/src/utils/photo_view_utils.dart
+++ b/mobile/lib/widgets/photo_view/src/utils/photo_view_utils.dart
@@ -9,25 +9,20 @@ double getScaleForScaleState(
PhotoViewScaleState scaleState,
ScaleBoundaries scaleBoundaries,
) {
- switch (scaleState) {
- case PhotoViewScaleState.initial:
- case PhotoViewScaleState.zoomedIn:
- case PhotoViewScaleState.zoomedOut:
- return _clampSize(scaleBoundaries.initialScale, scaleBoundaries);
- case PhotoViewScaleState.covering:
- return _clampSize(
+ return switch (scaleState) {
+ PhotoViewScaleState.initial ||
+ PhotoViewScaleState.zoomedIn ||
+ PhotoViewScaleState.zoomedOut =>
+ _clampSize(scaleBoundaries.initialScale, scaleBoundaries),
+ PhotoViewScaleState.covering => _clampSize(
_scaleForCovering(
scaleBoundaries.outerSize,
scaleBoundaries.childSize,
),
scaleBoundaries,
- );
- case PhotoViewScaleState.originalSize:
- return _clampSize(1.0, scaleBoundaries);
- // Will never be reached
- default:
- return 0;
- }
+ ),
+ PhotoViewScaleState.originalSize => _clampSize(1.0, scaleBoundaries),
+ };
}
/// Internal class to wraps custom scale boundaries (min, max and initial)
diff --git a/mobile/lib/widgets/settings/networking_settings/networking_settings.dart b/mobile/lib/widgets/settings/networking_settings/networking_settings.dart
index 59d05fd4cf..d241792d95 100644
--- a/mobile/lib/widgets/settings/networking_settings/networking_settings.dart
+++ b/mobile/lib/widgets/settings/networking_settings/networking_settings.dart
@@ -220,23 +220,20 @@ class NetworkStatusIcon extends StatelessWidget {
);
}
- Widget _buildIcon(BuildContext context) {
- switch (status) {
- case AuxCheckStatus.loading:
- return Padding(
- padding: const EdgeInsets.only(left: 4.0),
- child: SizedBox(
- width: 18,
- height: 18,
- child: CircularProgressIndicator(
- color: context.primaryColor,
- strokeWidth: 2,
- key: const ValueKey('loading'),
+ Widget _buildIcon(BuildContext context) => switch (status) {
+ AuxCheckStatus.loading => Padding(
+ padding: const EdgeInsets.only(left: 4.0),
+ child: SizedBox(
+ width: 18,
+ height: 18,
+ child: CircularProgressIndicator(
+ color: context.primaryColor,
+ strokeWidth: 2,
+ key: const ValueKey('loading'),
+ ),
),
),
- );
- case AuxCheckStatus.valid:
- return enabled
+ AuxCheckStatus.valid => enabled
? const Icon(
Icons.check_circle_rounded,
color: Colors.green,
@@ -246,9 +243,8 @@ class NetworkStatusIcon extends StatelessWidget {
Icons.check_circle_rounded,
color: context.colorScheme.onSurface.withAlpha(100),
key: const ValueKey('success'),
- );
- case AuxCheckStatus.error:
- return enabled
+ ),
+ AuxCheckStatus.error => enabled
? const Icon(
Icons.error_rounded,
color: Colors.red,
@@ -258,9 +254,7 @@ class NetworkStatusIcon extends StatelessWidget {
Icons.error_rounded,
color: Colors.grey,
key: ValueKey('error'),
- );
- default:
- return const Icon(Icons.circle_outlined, key: ValueKey('unknown'));
- }
- }
+ ),
+ _ => const Icon(Icons.circle_outlined, key: ValueKey('unknown')),
+ };
}