Skip to content

High performance self-hosted photo and video management solution.

chore(mobile): Add const linter (#14447)

Alex1bb6926b5e92
diff --git a/mobile/analysis_options.yaml b/mobile/analysis_options.yaml
index 7a20c2a6a3..2b4b810f2a 100644
--- a/mobile/analysis_options.yaml
+++ b/mobile/analysis_options.yaml
@@ -28,6 +28,7 @@ linter:
use_build_context_synchronously: false
require_trailing_commas: true
unrelated_type_equality_checks: true
+ prefer_const_constructors: true
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
diff --git a/mobile/lib/pages/albums/albums.page.dart b/mobile/lib/pages/albums/albums.page.dart
index e466149ac3..6f7d99b727 100644
--- a/mobile/lib/pages/albums/albums.page.dart
+++ b/mobile/lib/pages/albums/albums.page.dart
@@ -78,7 +78,7 @@ class AlbumsPage extends HookConsumerWidget {
showUploadButton: false,
actions: [
IconButton(
- icon: Icon(
+ icon: const Icon(
Icons.add_rounded,
size: 28,
),
@@ -112,13 +112,13 @@ class AlbumsPage extends HookConsumerWidget {
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
- transform: GradientRotation(0.5 * pi),
+ transform: const GradientRotation(0.5 * pi),
),
),
child: TextField(
autofocus: false,
decoration: InputDecoration(
- contentPadding: EdgeInsets.all(16),
+ contentPadding: const EdgeInsets.all(16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(
@@ -362,13 +362,13 @@ class SortButton extends ConsumerWidget {
return MenuAnchor(
style: MenuStyle(
- elevation: WidgetStatePropertyAll(1),
+ elevation: const WidgetStatePropertyAll(1),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
),
- padding: WidgetStatePropertyAll(
+ padding: const WidgetStatePropertyAll(
EdgeInsets.all(4),
),
),
diff --git a/mobile/lib/pages/common/album_options.page.dart b/mobile/lib/pages/common/album_options.page.dart
index d9f8544af9..93dfad00c4 100644
--- a/mobile/lib/pages/common/album_options.page.dart
+++ b/mobile/lib/pages/common/album_options.page.dart
@@ -49,7 +49,7 @@ class AlbumOptionsPage extends HookConsumerWidget {
if (isSuccess) {
context.navigateTo(
- TabControllerRoute(children: [AlbumsRoute()]),
+ const TabControllerRoute(children: [AlbumsRoute()]),
);
} else {
showErrorMessage();
diff --git a/mobile/lib/pages/common/album_shared_user_selection.page.dart b/mobile/lib/pages/common/album_shared_user_selection.page.dart
index 9dadef1a76..ed8a45194d 100644
--- a/mobile/lib/pages/common/album_shared_user_selection.page.dart
+++ b/mobile/lib/pages/common/album_shared_user_selection.page.dart
@@ -33,7 +33,7 @@ class AlbumSharedUserSelectionPage extends HookConsumerWidget {
if (newAlbum != null) {
ref.watch(albumTitleProvider.notifier).clearAlbumTitle();
context.maybePop(true);
- context.navigateTo(TabControllerRoute(children: [AlbumsRoute()]));
+ context.navigateTo(const TabControllerRoute(children: [AlbumsRoute()]));
}
ScaffoldMessenger(
diff --git a/mobile/lib/pages/library/library.page.dart b/mobile/lib/pages/library/library.page.dart
index 837005c175..92fe8cec17 100644
--- a/mobile/lib/pages/library/library.page.dart
+++ b/mobile/lib/pages/library/library.page.dart
@@ -28,7 +28,7 @@ class LibraryPage extends ConsumerWidget {
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
return Scaffold(
- appBar: ImmichAppBar(),
+ appBar: const ImmichAppBar(),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ListView(
@@ -81,7 +81,7 @@ class LibraryPage extends ConsumerWidget {
],
),
const SizedBox(height: 12),
- QuickAccessButtons(),
+ const QuickAccessButtons(),
const SizedBox(
height: 32,
),
@@ -122,8 +122,8 @@ class QuickAccessButtons extends ConsumerWidget {
ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
- topLeft: Radius.circular(20),
- topRight: Radius.circular(20),
+ topLeft: const Radius.circular(20),
+ topRight: const Radius.circular(20),
bottomLeft: Radius.circular(partners.isEmpty ? 20 : 0),
bottomRight: Radius.circular(partners.isEmpty ? 20 : 0),
),
@@ -173,7 +173,7 @@ class PartnerList extends ConsumerWidget {
right: 18.0,
),
leading: userAvatar(context, partner, radius: 16),
- title: Text(
+ title: const Text(
"partner_list_user_photos",
style: TextStyle(
fontWeight: FontWeight.w500,
diff --git a/mobile/lib/pages/library/places/places_collection.page.dart b/mobile/lib/pages/library/places/places_collection.page.dart
index 3e4f9f6a1d..f42febc373 100644
--- a/mobile/lib/pages/library/places/places_collection.page.dart
+++ b/mobile/lib/pages/library/places/places_collection.page.dart
@@ -60,7 +60,7 @@ class PlacesCollectionPage extends HookConsumerWidget {
);
},
error: (error, stask) => const Text('Error getting places'),
- loading: () => Center(child: const CircularProgressIndicator()),
+ loading: () => const Center(child: CircularProgressIndicator()),
),
],
),
diff --git a/mobile/lib/pages/search/search.page.dart b/mobile/lib/pages/search/search.page.dart
index 82d7c0a168..9f2ddee446 100644
--- a/mobile/lib/pages/search/search.page.dart
+++ b/mobile/lib/pages/search/search.page.dart
@@ -499,8 +499,8 @@ class SearchPage extends HookConsumerWidget {
controller: textSearchController,
decoration: InputDecoration(
contentPadding: prefilter != null
- ? EdgeInsets.only(left: 24)
- : EdgeInsets.all(8),
+ ? const EdgeInsets.only(left: 24)
+ : const EdgeInsets.all(8),
prefixIcon: prefilter != null
? null
: Icon(
@@ -647,7 +647,9 @@ class SearchResultGrid extends StatelessWidget {
stackEnabled: false,
emptyIndicator: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
- child: !isSearching ? SearchEmptyContent() : SizedBox.shrink(),
+ child: !isSearching
+ ? const SearchEmptyContent()
+ : const SizedBox.shrink(),
),
),
),
@@ -666,7 +668,7 @@ class SearchEmptyContent extends StatelessWidget {
child: ListView(
shrinkWrap: false,
children: [
- SizedBox(height: 40),
+ const SizedBox(height: 40),
Center(
child: Image.asset(
context.isDarkTheme
@@ -675,15 +677,15 @@ class SearchEmptyContent extends StatelessWidget {
height: 125,
),
),
- SizedBox(height: 16),
+ const SizedBox(height: 16),
Center(
child: Text(
"Search for your photos and videos",
style: context.textTheme.labelLarge,
),
),
- SizedBox(height: 32),
- QuickLinkList(),
+ const SizedBox(height: 32),
+ const QuickLinkList(),
],
),
);
@@ -725,13 +727,13 @@ class QuickLinkList extends StatelessWidget {
QuickLink(
title: 'videos'.tr(),
icon: Icons.play_circle_outline_rounded,
- onTap: () => context.pushRoute(AllVideosRoute()),
+ onTap: () => context.pushRoute(const AllVideosRoute()),
),
QuickLink(
title: 'favorites'.tr(),
icon: Icons.favorite_border_rounded,
isBottom: true,
- onTap: () => context.pushRoute(FavoritesRoute()),
+ onTap: () => context.pushRoute(const FavoritesRoute()),
),
],
),
diff --git a/mobile/lib/repositories/auth_api.repository.dart b/mobile/lib/repositories/auth_api.repository.dart
index faa2916adb..f3a1d52de3 100644
--- a/mobile/lib/repositories/auth_api.repository.dart
+++ b/mobile/lib/repositories/auth_api.repository.dart
@@ -39,7 +39,9 @@ class AuthApiRepository extends ApiRepository implements IAuthApiRepository {
@override
Future<void> logout() async {
- await _apiService.authenticationApi.logout().timeout(Duration(seconds: 7));
+ await _apiService.authenticationApi
+ .logout()
+ .timeout(const Duration(seconds: 7));
}
_mapLoginReponse(LoginResponseDto dto) {
diff --git a/mobile/lib/services/api.service.dart b/mobile/lib/services/api.service.dart
index bd754ac214..63cd3f9f8c 100644
--- a/mobile/lib/services/api.service.dart
+++ b/mobile/lib/services/api.service.dart
@@ -104,7 +104,7 @@ class ApiService implements Authentication {
try {
await setEndpoint(serverUrl);
- await serverInfoApi.pingServer().timeout(Duration(seconds: 5));
+ await serverInfoApi.pingServer().timeout(const Duration(seconds: 5));
} on TimeoutException catch (_) {
return false;
} on SocketException catch (_) {
diff --git a/mobile/lib/utils/immich_app_theme.dart b/mobile/lib/utils/immich_app_theme.dart
index da47490651..2ca4fe3aff 100644
--- a/mobile/lib/utils/immich_app_theme.dart
+++ b/mobile/lib/utils/immich_app_theme.dart
@@ -198,7 +198,7 @@ ThemeData getThemeData({
scrolledUnderElevation: 0,
centerTitle: true,
),
- textTheme: TextTheme(
+ textTheme: const TextTheme(
displayLarge: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
@@ -211,15 +211,15 @@ ThemeData getThemeData({
fontSize: 12,
fontWeight: FontWeight.bold,
),
- titleSmall: const TextStyle(
+ titleSmall: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
- titleMedium: const TextStyle(
+ titleMedium: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
- titleLarge: const TextStyle(
+ titleLarge: TextStyle(
fontSize: 26.0,
fontWeight: FontWeight.bold,
),
diff --git a/mobile/lib/widgets/album/album_viewer_appbar.dart b/mobile/lib/widgets/album/album_viewer_appbar.dart
index 89528cc4da..525bfa1242 100644
--- a/mobile/lib/widgets/album/album_viewer_appbar.dart
+++ b/mobile/lib/widgets/album/album_viewer_appbar.dart
@@ -46,7 +46,7 @@ class AlbumViewerAppbar extends HookConsumerWidget
final bool success;
if (album.shared) {
success = await ref.watch(albumProvider.notifier).deleteAlbum(album);
- context.navigateTo(TabControllerRoute(children: [AlbumsRoute()]));
+ context.navigateTo(const TabControllerRoute(children: [AlbumsRoute()]));
} else {
success = await ref.watch(albumProvider.notifier).deleteAlbum(album);
context
@@ -113,7 +113,7 @@ class AlbumViewerAppbar extends HookConsumerWidget
await ref.watch(albumProvider.notifier).leaveAlbum(album);
if (isSuccess) {
- context.navigateTo(TabControllerRoute(children: [AlbumsRoute()]));
+ context.navigateTo(const TabControllerRoute(children: [AlbumsRoute()]));
} else {
context.pop();
ImmichToast.show(
diff --git a/mobile/lib/widgets/asset_viewer/bottom_gallery_bar.dart b/mobile/lib/widgets/asset_viewer/bottom_gallery_bar.dart
index f698e866ad..82ca295d8a 100644
--- a/mobile/lib/widgets/asset_viewer/bottom_gallery_bar.dart
+++ b/mobile/lib/widgets/asset_viewer/bottom_gallery_bar.dart
@@ -338,7 +338,7 @@ class BottomGalleryBar extends ConsumerWidget {
),
position: DecorationPosition.background,
child: Padding(
- padding: EdgeInsets.only(top: 40.0),
+ padding: const EdgeInsets.only(top: 40.0),
child: Column(
children: [
if (showVideoPlayerControls) const VideoControls(),
diff --git a/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart b/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart
index a83afc00b3..218e17cbe1 100644
--- a/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart
+++ b/mobile/lib/widgets/common/app_bar_dialog/app_bar_dialog.dart
@@ -143,9 +143,9 @@ class ImmichAppBarDialog extends HookConsumerWidget {
);
},
trailing: isLoggingOut.value
- ? SizedBox.square(
+ ? const SizedBox.square(
dimension: 20,
- child: const CircularProgressIndicator(strokeWidth: 2),
+ child: CircularProgressIndicator(strokeWidth: 2),
)
: null,
);
diff --git a/mobile/test/modules/map/map_theme_override_test.dart b/mobile/test/modules/map/map_theme_override_test.dart
index b462ede4c5..c21f9bf166 100644
--- a/mobile/test/modules/map/map_theme_override_test.dart
+++ b/mobile/test/modules/map/map_theme_override_test.dart
@@ -27,7 +27,7 @@ void main() {
mapStateNotifier = MockMapStateNotifier(mapState);
overrides = [
mapStateNotifierProvider.overrideWith(() => mapStateNotifier),
- localeProvider.overrideWithValue(Locale("en")),
+ localeProvider.overrideWithValue(const Locale("en")),
];
});