From 7432689bb1bb2705d8e2765884805bc9cf0318f1 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:01:25 +0530 Subject: [PATCH 1/6] Support sending logs on password verification screen --- lib/core/configuration.dart | 11 +++++ lib/ui/account/password_reentry_page.dart | 31 +++++++++++++- lib/utils/validator_util.dart | 50 +++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 lib/utils/validator_util.dart diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index f705dd54c..0cdfc3727 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -29,6 +29,7 @@ import 'package:photos/services/memories_service.dart'; import 'package:photos/services/search_service.dart'; import 'package:photos/services/sync_service.dart'; import 'package:photos/utils/crypto_util.dart'; +import 'package:photos/utils/validator_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:uuid/uuid.dart'; import 'package:wakelock/wakelock.dart'; @@ -242,12 +243,18 @@ class Configuration { String password, KeyAttributes attributes, ) async { + _logger.info('Start decryptAndSaveSecrets'); + validatePreVerificationStateCheck( + attributes, password, getEncryptedToken()); + _logger.info('state validation done'); final kek = await CryptoUtil.deriveKey( utf8.encode(password), Sodium.base642bin(attributes.kekSalt), attributes.memLimit, attributes.opsLimit, ); + + _logger.info('user-key done'); Uint8List key; try { key = CryptoUtil.decryptSync( @@ -256,20 +263,24 @@ class Configuration { Sodium.base642bin(attributes.keyDecryptionNonce), ); } catch (e) { + _logger.severe('master-key failed, incorrect password?'); throw Exception("Incorrect password"); } + _logger.info("master-key done"); await setKey(Sodium.bin2base64(key)); final secretKey = CryptoUtil.decryptSync( Sodium.base642bin(attributes.encryptedSecretKey), key, Sodium.base642bin(attributes.secretKeyDecryptionNonce), ); + _logger.info("secret-key done"); await setSecretKey(Sodium.bin2base64(secretKey)); final token = CryptoUtil.openSealSync( Sodium.base642bin(getEncryptedToken()), Sodium.base642bin(attributes.publicKey), secretKey, ); + _logger.info('appToken done'); await setToken( Sodium.bin2base64(token, variant: Sodium.base64VariantUrlsafe), ); diff --git a/lib/ui/account/password_reentry_page.dart b/lib/ui/account/password_reentry_page.dart index 30d51e138..ad89437d0 100644 --- a/lib/ui/account/password_reentry_page.dart +++ b/lib/ui/account/password_reentry_page.dart @@ -3,10 +3,13 @@ import 'package:logging/logging.dart'; import 'package:photos/core/configuration.dart'; import 'package:photos/core/event_bus.dart'; import 'package:photos/events/subscription_purchased_event.dart'; +import 'package:photos/models/key_attributes.dart'; import 'package:photos/ui/account/recovery_page.dart'; +import 'package:photos/ui/common/dialogs.dart'; import 'package:photos/ui/common/dynamic_fab.dart'; import 'package:photos/ui/home_widget.dart'; import 'package:photos/utils/dialog_util.dart'; +import 'package:photos/utils/email_util.dart'; class PasswordReentryPage extends StatefulWidget { const PasswordReentryPage({Key key}) : super(key: key); @@ -16,6 +19,7 @@ class PasswordReentryPage extends StatefulWidget { } class _PasswordReentryPageState extends State { + final _logger = Logger((_PasswordReentryPageState).toString()); final _passwordController = TextEditingController(); final FocusNode _passwordFocusNode = FocusNode(); String email; @@ -72,9 +76,26 @@ class _PasswordReentryPageState extends State { Configuration.instance.getKeyAttributes(), ); } catch (e, s) { - Logger("PRP").severe("Password verification failed", e, s); + _logger.severe("Password verification failed", e, s); await dialog.hide(); - showErrorDialog(context, "Incorrect password", "Please try again"); + + var dialogUserChoice = await showChoiceDialog( + context, + "Incorrect password", + "Please try again", + firstAction: "Contact Support", + firstActionColor: Theme.of(context).colorScheme.primary, + secondAction: "Ok", + secondActionColor: Theme.of(context).colorScheme.primary, + ); + if (dialogUserChoice == DialogUserChoice.firstChoice) { + await sendLogs( + context, + "Contact support", + "support@ente.io", + postShare: () {}, + ); + } return; } await dialog.hide(); @@ -231,4 +252,10 @@ class _PasswordReentryPageState extends State { ], ); } + + void validatePreVerificationState(KeyAttributes keyAttributes) { + if (keyAttributes == null) { + throw Exception("Key Attributes can not be null"); + } + } } diff --git a/lib/utils/validator_util.dart b/lib/utils/validator_util.dart new file mode 100644 index 000000000..cd6cc41ee --- /dev/null +++ b/lib/utils/validator_util.dart @@ -0,0 +1,50 @@ +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:logging/logging.dart'; +import 'package:photos/models/key_attributes.dart'; + +Logger _logger = Logger("Validator"); + +void validatePreVerificationStateCheck( + KeyAttributes keyAttr, + String password, + String encryptedToken, +) { + nullOrEmptyArgCheck(encryptedToken, "encryptedToken"); + nullOrEmptyArgCheck(password, "userPassword"); + if (keyAttr == null) { + throw ArgumentError("key Attributes can not be null"); + } + nullOrEmptyArgCheck(keyAttr.kekSalt, "keySalt"); + nullOrEmptyArgCheck(keyAttr.encryptedKey, "encryptedKey"); + nullOrEmptyArgCheck(keyAttr.keyDecryptionNonce, "keyDecryptionNonce"); + nullOrEmptyArgCheck(keyAttr.encryptedSecretKey, "encryptedSecretKey"); + nullOrEmptyArgCheck( + keyAttr.secretKeyDecryptionNonce, + "secretKeyDecryptionNonce", + ); + nullOrEmptyArgCheck(keyAttr.publicKey, "publicKey"); + if ((keyAttr.memLimit ?? 0) <= 0 || (keyAttr.opsLimit ?? 0) <= 0) { + throw ArgumentError("Key mem/OpsLimit can not be null or <0"); + } + // check password encoding issues + try { + Uint8List passwordL = utf8.encode(password); + try { + utf8.decode(passwordL); + } catch (e) { + _logger.severe("CRITICAL: password decode failed", e); + rethrow; + } + } catch (e) { + _logger.severe('CRITICAL: password encode failed'); + rethrow; + } +} + +void nullOrEmptyArgCheck(String value, String name) { + if (value == null || value.isEmpty) { + throw ArgumentError("Critical: $name is nullOrEmpty"); + } +} From bb0af1c795a404258c3ab12c7c05c423dceff47c Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:02:17 +0530 Subject: [PATCH 2/6] bump version code to 0.6.28+358 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 552de205e..ad635b170 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: ente photos application # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.6.26+356 +version: 0.6.28+358 environment: sdk: ">=2.10.0 <3.0.0" From ba82402969a6c163f657c1228d9d2b8dabf3c9a7 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:23:09 +0530 Subject: [PATCH 3/6] log actual exception --- lib/core/configuration.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index 0cdfc3727..c00b648a6 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -245,7 +245,10 @@ class Configuration { ) async { _logger.info('Start decryptAndSaveSecrets'); validatePreVerificationStateCheck( - attributes, password, getEncryptedToken()); + attributes, + password, + getEncryptedToken(), + ); _logger.info('state validation done'); final kek = await CryptoUtil.deriveKey( utf8.encode(password), @@ -263,7 +266,7 @@ class Configuration { Sodium.base642bin(attributes.keyDecryptionNonce), ); } catch (e) { - _logger.severe('master-key failed, incorrect password?'); + _logger.severe('master-key failed, incorrect password?', e); throw Exception("Incorrect password"); } _logger.info("master-key done"); From 6d48964a7b543fbce5997a5fb1bb8b252e75a6d4 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:23:26 +0530 Subject: [PATCH 4/6] bump version code to 0.6.29+359 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index ad635b170..401ff506b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: ente photos application # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.6.28+358 +version: 0.6.29+359 environment: sdk: ">=2.10.0 <3.0.0" From 06ec7cb658af04ca280f97954a2283ba107dffad Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Mon, 29 Aug 2022 20:13:31 +0530 Subject: [PATCH 5/6] final all the vars! --- analysis_options.yaml | 1 + lib/core/cache/lru_map.dart | 6 ++--- lib/core/configuration.dart | 2 +- lib/core/error-reporting/super_logging.dart | 20 ++++++++--------- lib/db/collections_db.dart | 10 ++++----- lib/db/file_migration_db.dart | 4 ++-- lib/db/files_db.dart | 22 +++++++++---------- lib/db/ignored_files_db.dart | 4 ++-- lib/db/memories_db.dart | 6 ++--- lib/db/public_keys_db.dart | 6 ++--- lib/db/trash_db.dart | 8 +++---- lib/db/upload_locks_db.dart | 4 ++-- lib/ente_theme_data.dart | 14 +++++------- lib/main.dart | 12 +++++----- lib/models/collection.dart | 2 +- lib/models/file.dart | 2 +- lib/models/selected_files.dart | 6 ++--- lib/models/subscription.dart | 2 +- lib/services/collections_service.dart | 4 ++-- lib/services/deduplication_service.dart | 2 +- lib/services/favorites_service.dart | 2 +- lib/services/feature_flag_service.dart | 2 +- lib/services/file_magic_service.dart | 8 +++---- lib/services/file_migration_service.dart | 12 +++++----- lib/services/local_sync_service.dart | 10 ++++----- lib/services/remote_sync_service.dart | 8 +++---- lib/services/user_service.dart | 4 ++-- lib/ui/account/delete_account_page.dart | 4 ++-- lib/ui/account/password_reentry_page.dart | 2 +- lib/ui/account/recovery_key_page.dart | 2 +- lib/ui/account/sessions_page.dart | 4 ++-- lib/ui/account/two_factor_setup_page.dart | 4 ++-- .../collections/collection_item_widget.dart | 8 +++---- .../remote_collections_grid_view_widget.dart | 4 ++-- lib/ui/common/dialogs.dart | 2 +- lib/ui/create_collection_page.dart | 4 ++-- lib/ui/grant_permissions_widget.dart | 2 +- lib/ui/home_widget.dart | 6 ++--- lib/ui/huge_listview/draggable_scrollbar.dart | 2 +- lib/ui/huge_listview/huge_listview.dart | 2 +- .../huge_listview/lazy_loading_gallery.dart | 4 ++-- lib/ui/memories_widget.dart | 4 ++-- lib/ui/nav_bar.dart | 2 +- lib/ui/payment/payment_web_page.dart | 16 +++++++------- lib/ui/payment/stripe_subscription_page.dart | 12 +++++----- .../payment/subscription_common_widgets.dart | 2 +- lib/ui/payment/subscription_plan_widget.dart | 4 ++-- lib/ui/settings/account_section_widget.dart | 6 ++--- lib/ui/settings/app_update_dialog.dart | 2 +- lib/ui/settings/app_version_widget.dart | 2 +- lib/ui/settings/backup_section_widget.dart | 12 +++++----- lib/ui/settings/danger_section_widget.dart | 2 +- lib/ui/settings/debug_section_widget.dart | 2 +- lib/ui/settings/security_section_widget.dart | 6 ++--- lib/ui/settings/social_section_widget.dart | 2 +- lib/ui/shared_collections_gallery.dart | 14 ++++++------ lib/ui/sharing/manage_links_widget.dart | 18 +++++++-------- lib/ui/sharing/share_collection_widget.dart | 8 +++---- lib/ui/status_bar_widget.dart | 2 +- lib/ui/tools/editor/filtered_image.dart | 10 ++++----- lib/ui/tools/editor/image_editor_page.dart | 16 +++++++------- lib/ui/viewer/file/custom_app_bar.dart | 1 + lib/ui/viewer/file/detail_page.dart | 2 +- lib/ui/viewer/file/fading_app_bar.dart | 6 ++--- lib/ui/viewer/file/fading_bottom_bar.dart | 6 ++--- lib/ui/viewer/file/file_info_dialog.dart | 4 ++-- lib/ui/viewer/file/thumbnail_widget.dart | 4 ++-- lib/ui/viewer/file/video_controls.dart | 2 +- lib/ui/viewer/file/zoomable_image.dart | 2 +- lib/ui/viewer/file/zoomable_live_image.dart | 6 ++--- lib/ui/viewer/gallery/gallery.dart | 6 ++--- .../gallery/gallery_app_bar_widget.dart | 4 ++-- .../gallery/gallery_overlay_widget.dart | 6 ++--- lib/ui/viewer/gallery/trash_page.dart | 2 +- lib/utils/data_util.dart | 4 ++-- lib/utils/date_time_util.dart | 12 +++++----- lib/utils/delete_file_util.dart | 4 ++-- lib/utils/dialog_util.dart | 4 ++-- lib/utils/diff_fetcher.dart | 2 +- lib/utils/email_util.dart | 12 +++++----- lib/utils/file_sync_util.dart | 2 +- lib/utils/file_uploader.dart | 14 ++++++------ lib/utils/file_uploader_util.dart | 8 +++---- lib/utils/file_util.dart | 20 ++++++++--------- lib/utils/hex.dart | 8 +++---- lib/utils/magic_util.dart | 4 ++-- lib/utils/share_util.dart | 8 +++---- lib/utils/trash_diff_fetcher.dart | 2 +- lib/utils/validator_util.dart | 2 +- 89 files changed, 265 insertions(+), 267 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index fb913d542..0537fc253 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -15,6 +15,7 @@ linter: - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables + - prefer_final_locals - require_trailing_commas - sized_box_for_whitespace - use_full_hex_values_for_flutter_colors diff --git a/lib/core/cache/lru_map.dart b/lib/core/cache/lru_map.dart index 6df069472..3b588ffc4 100644 --- a/lib/core/cache/lru_map.dart +++ b/lib/core/cache/lru_map.dart @@ -10,7 +10,7 @@ class LRUMap { LRUMap(this._maxSize, [this._handler]); V get(K key) { - V value = _map.remove(key); + final V value = _map.remove(key); if (value != null) { _map[key] = value; } @@ -21,8 +21,8 @@ class LRUMap { _map.remove(key); _map[key] = value; if (_map.length > _maxSize) { - K evictedKey = _map.keys.first; - V evictedValue = _map.remove(evictedKey); + final K evictedKey = _map.keys.first; + final V evictedValue = _map.remove(evictedKey); if (_handler != null) { _handler(evictedKey, evictedValue); } diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index c00b648a6..9b7d6182e 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -112,7 +112,7 @@ class Configuration { _logger.warning(e); } tempDirectory.createSync(recursive: true); - var tempDirectoryPath = (await getTemporaryDirectory()).path; + final tempDirectoryPath = (await getTemporaryDirectory()).path; _thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache"; io.Directory(_thumbnailCacheDirectory).createSync(recursive: true); _sharedTempMediaDirectory = tempDirectoryPath + "/ente-shared-media"; diff --git a/lib/core/error-reporting/super_logging.dart b/lib/core/error-reporting/super_logging.dart index bec7e9588..3884d0e78 100644 --- a/lib/core/error-reporting/super_logging.dart +++ b/lib/core/error-reporting/super_logging.dart @@ -23,7 +23,7 @@ extension SuperString on String { var start = 0; while (true) { - var stop = start + chunkSize; + final stop = start + chunkSize; if (stop > length) break; yield substring(start, stop); start = stop; @@ -37,7 +37,7 @@ extension SuperString on String { extension SuperLogRecord on LogRecord { String toPrettyString([String extraLines]) { - var header = "[$loggerName] [$level] [$time]"; + final header = "[$loggerName] [$level] [$time]"; var msg = "$header $message"; @@ -236,7 +236,7 @@ class SuperLogging { extraLines = null; } - var str = config.prefix + " " + rec.toPrettyString(extraLines); + final str = config.prefix + " " + rec.toPrettyString(extraLines); // write to stdout printLog(str); @@ -316,21 +316,21 @@ class SuperLogging { // choose [logDir] if (dirPath.isEmpty) { - var root = await getExternalStorageDirectory(); + final root = await getExternalStorageDirectory(); dirPath = '${root.path}/logs'; } // create [logDir] - var dir = Directory(dirPath); + final dir = Directory(dirPath); await dir.create(recursive: true); - var files = []; - var dates = {}; + final files = []; + final dates = {}; // collect all log files with valid names await for (final file in dir.list()) { try { - var date = config.dateFmt.parse(basename(file.path)); + final date = config.dateFmt.parse(basename(file.path)); dates[file as File] = date; files.add(file); } on FormatException {} @@ -363,7 +363,7 @@ class SuperLogging { static String appVersion; static Future getAppVersion() async { - var pkgInfo = await PackageInfo.fromPlatform(); + final pkgInfo = await PackageInfo.fromPlatform(); return "${pkgInfo.version}+${pkgInfo.buildNumber}"; } @@ -372,7 +372,7 @@ class SuperLogging { if (!Platform.isAndroid) { return false; } - var pkgName = (await PackageInfo.fromPlatform()).packageName; + final pkgName = (await PackageInfo.fromPlatform()).packageName; return pkgName.startsWith("io.ente.photos.fdroid"); } } diff --git a/lib/db/collections_db.dart b/lib/db/collections_db.dart index a676ee5a0..d83fed142 100644 --- a/lib/db/collections_db.dart +++ b/lib/db/collections_db.dart @@ -60,8 +60,8 @@ class CollectionsDB { } Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabaseWithMigration(path, dbConfig); } @@ -157,7 +157,7 @@ class CollectionsDB { Future> insert(List collections) async { final db = await instance.database; - var batch = db.batch(); + final batch = db.batch(); for (final collection in collections) { batch.insert( table, @@ -202,7 +202,7 @@ class CollectionsDB { } Map _getRowForCollection(Collection collection) { - var row = {}; + final row = {}; row[columnID] = collection.id; row[columnOwner] = collection.owner.toJson(); row[columnEncryptedKey] = collection.encryptedKey; @@ -230,7 +230,7 @@ class CollectionsDB { } Collection _convertToCollection(Map row) { - Collection result = Collection( + final Collection result = Collection( row[columnID], User.fromJson(row[columnOwner]), row[columnEncryptedKey], diff --git a/lib/db/file_migration_db.dart b/lib/db/file_migration_db.dart index 3859b6292..43e9f7b04 100644 --- a/lib/db/file_migration_db.dart +++ b/lib/db/file_migration_db.dart @@ -40,8 +40,8 @@ class FilesMigrationDB { // this opens the database (and creates it if it doesn't exist) Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabase( path, version: _databaseVersion, diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart index a34de3974..81cf8a252 100644 --- a/lib/db/files_db.dart +++ b/lib/db/files_db.dart @@ -95,8 +95,8 @@ class FilesDB { // this opens the database (and creates it if it doesn't exist) Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); _logger.info("DB path " + path); return await openDatabaseWithMigration(path, dbConfig); } @@ -425,7 +425,7 @@ class FilesDB { limit: limit, ); final files = _convertToFiles(results); - List deduplicatedFiles = + final List deduplicatedFiles = _deduplicatedAndFilterIgnoredFiles(files, ignoredCollectionIDs); return FileLoadResult(deduplicatedFiles, files.length == limit); } @@ -451,7 +451,7 @@ class FilesDB { limit: limit, ); final files = _convertToFiles(results); - List deduplicatedFiles = + final List deduplicatedFiles = _deduplicatedAndFilterIgnoredFiles(files, ignoredCollectionIDs); return FileLoadResult(deduplicatedFiles, files.length == limit); } @@ -483,7 +483,7 @@ class FilesDB { limit: limit, ); final files = _convertToFiles(results); - List deduplicatedFiles = + final List deduplicatedFiles = _deduplicatedAndFilterIgnoredFiles(files, ignoredCollectionIDs); return FileLoadResult(deduplicatedFiles, files.length == limit); } @@ -674,7 +674,7 @@ class FilesDB { orderBy: '$columnCreationTime DESC', groupBy: columnLocalID, ); - var files = _convertToFiles(results); + final files = _convertToFiles(results); // future-safe filter just to ensure that the query doesn't end up returning files // which should not be backed up files.removeWhere( @@ -937,7 +937,7 @@ class FilesDB { Future collectionFileCount(int collectionID) async { final db = await instance.database; - var count = Sqflite.firstIntValue( + final count = Sqflite.firstIntValue( await db.rawQuery( 'SELECT COUNT(*) FROM $table where $columnCollectionID = $collectionID', ), @@ -947,7 +947,7 @@ class FilesDB { Future fileCountWithVisibility(int visibility, int ownerID) async { final db = await instance.database; - var count = Sqflite.firstIntValue( + final count = Sqflite.firstIntValue( await db.rawQuery( 'SELECT COUNT(*) FROM $table where $columnMMdVisibility = $visibility AND $columnOwnerID = $ownerID', ), @@ -1152,9 +1152,9 @@ class FilesDB { Future> getAllFilesFromDB() async { final db = await instance.database; - List> result = await db.query(table); - List files = _convertToFiles(result); - List deduplicatedFiles = + final List> result = await db.query(table); + final List files = _convertToFiles(result); + final List deduplicatedFiles = _deduplicatedAndFilterIgnoredFiles(files, null); return deduplicatedFiles; } diff --git a/lib/db/ignored_files_db.dart b/lib/db/ignored_files_db.dart index 1d36aece0..6cb526e38 100644 --- a/lib/db/ignored_files_db.dart +++ b/lib/db/ignored_files_db.dart @@ -52,8 +52,8 @@ class IgnoredFilesDB { // this opens the database (and creates it if it doesn't exist) Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabase( path, version: _databaseVersion, diff --git a/lib/db/memories_db.dart b/lib/db/memories_db.dart index 9fab1ae2e..736912644 100644 --- a/lib/db/memories_db.dart +++ b/lib/db/memories_db.dart @@ -25,8 +25,8 @@ class MemoriesDB { } Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabase( path, version: _databaseVersion, @@ -74,7 +74,7 @@ class MemoriesDB { } Map _getRowForSeenMemory(Memory memory, int timestamp) { - var row = {}; + final row = {}; row[columnFileID] = memory.file.generatedID; row[columnSeenTime] = timestamp; return row; diff --git a/lib/db/public_keys_db.dart b/lib/db/public_keys_db.dart index 2b11b0b3d..aea09ea1a 100644 --- a/lib/db/public_keys_db.dart +++ b/lib/db/public_keys_db.dart @@ -26,8 +26,8 @@ class PublicKeysDB { } Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabase( path, version: _databaseVersion, @@ -72,7 +72,7 @@ class PublicKeysDB { } Map _getRow(PublicKey key) { - var row = {}; + final row = {}; row[columnEmail] = key.email; row[columnPublicKey] = key.publicKey; return row; diff --git a/lib/db/trash_db.dart b/lib/db/trash_db.dart index 3d7b9c474..b84e4ca8b 100644 --- a/lib/db/trash_db.dart +++ b/lib/db/trash_db.dart @@ -85,8 +85,8 @@ class TrashDB { // this opens the database (and creates it if it doesn't exist) Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); _logger.info("DB path " + path); return await openDatabase( path, @@ -103,7 +103,7 @@ class TrashDB { // getRecentlyTrashedFile returns the file which was trashed recently Future getRecentlyTrashedFile() async { final db = await instance.database; - var rows = await db.query( + final rows = await db.query( tableName, orderBy: '$columnTrashDeleteBy DESC', limit: 1, @@ -116,7 +116,7 @@ class TrashDB { Future count() async { final db = await instance.database; - var count = Sqflite.firstIntValue( + final count = Sqflite.firstIntValue( await db.rawQuery('SELECT COUNT(*) FROM $tableName'), ); return count; diff --git a/lib/db/upload_locks_db.dart b/lib/db/upload_locks_db.dart index 18a42cda4..1739a695f 100644 --- a/lib/db/upload_locks_db.dart +++ b/lib/db/upload_locks_db.dart @@ -24,8 +24,8 @@ class UploadLocksDB { } Future _initDatabase() async { - Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, _databaseName); + final Directory documentsDirectory = await getApplicationDocumentsDirectory(); + final String path = join(documentsDirectory.path, _databaseName); return await openDatabase( path, version: _databaseVersion, diff --git a/lib/ente_theme_data.dart b/lib/ente_theme_data.dart index 8ba243e6b..706858ec5 100644 --- a/lib/ente_theme_data.dart +++ b/lib/ente_theme_data.dart @@ -10,11 +10,6 @@ final lightThemeData = ThemeData( iconTheme: const IconThemeData(color: Colors.black), primaryIconTheme: const IconThemeData(color: Colors.red, opacity: 1.0, size: 50.0), - colorScheme: const ColorScheme.light( - primary: Colors.black, - secondary: Color.fromARGB(255, 163, 163, 163), - ), - accentColor: const Color.fromRGBO(0, 0, 0, 0.6), outlinedButtonTheme: buildOutlinedButtonThemeData( bgDisabled: Colors.grey.shade500, bgEnabled: Colors.black, @@ -78,7 +73,10 @@ final lightThemeData = ThemeData( ? Colors.white : Colors.black; }), - ), + ), colorScheme: const ColorScheme.light( + primary: Colors.black, + secondary: Color.fromARGB(255, 163, 163, 163), + ).copyWith(secondary: const Color.fromRGBO(0, 0, 0, 0.6)), ); final darkThemeData = ThemeData( @@ -89,8 +87,6 @@ final darkThemeData = ThemeData( primaryIconTheme: const IconThemeData(color: Colors.red, opacity: 1.0, size: 50.0), hintColor: Colors.grey, - colorScheme: const ColorScheme.dark(primary: Colors.white), - accentColor: const Color.fromRGBO(45, 194, 98, 0.2), buttonTheme: const ButtonThemeData().copyWith( buttonColor: const Color.fromRGBO(45, 194, 98, 1.0), ), @@ -154,7 +150,7 @@ final darkThemeData = ThemeData( return Colors.grey; } }), - ), + ), colorScheme: const ColorScheme.dark(primary: Colors.white).copyWith(secondary: const Color.fromRGBO(45, 194, 98, 0.2)), ); TextTheme _buildTextTheme(Color textColor) { diff --git a/lib/main.dart b/lib/main.dart index 044f8b9ec..ff88f8e1b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -231,8 +231,8 @@ Future _killBGTask([String taskId]) async { } Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { - bool isRunningInFG = await _isRunningInForeground(); // hb - bool isInForeground = AppLifecycleService.instance.isForeground; + final bool isRunningInFG = await _isRunningInForeground(); // hb + final bool isInForeground = AppLifecycleService.instance.isForeground; if (_isProcessRunning) { _logger.info( "Background push received when app is alive and runningInFS: $isRunningInFG inForeground: $isInForeground", @@ -259,18 +259,18 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { } Future _logFGHeartBeatInfo() async { - bool isRunningInFG = await _isRunningInForeground(); + final bool isRunningInFG = await _isRunningInForeground(); final prefs = await SharedPreferences.getInstance(); await prefs.reload(); - var lastFGTaskHeartBeatTime = prefs.getInt(kLastFGTaskHeartBeatTime) ?? 0; - String lastRun = lastFGTaskHeartBeatTime == 0 + final lastFGTaskHeartBeatTime = prefs.getInt(kLastFGTaskHeartBeatTime) ?? 0; + final String lastRun = lastFGTaskHeartBeatTime == 0 ? 'never' : DateTime.fromMicrosecondsSinceEpoch(lastFGTaskHeartBeatTime).toString(); _logger.info('isAlreaduunningFG: $isRunningInFG, last Beat: $lastRun'); } void _scheduleSuicide(Duration duration, [String taskID]) { - var taskIDVal = taskID ?? 'no taskID'; + final taskIDVal = taskID ?? 'no taskID'; _logger.warning("Schedule seppuku taskID: $taskIDVal"); Future.delayed(duration, () { _logger.warning("TLE, committing seppuku for taskID: $taskIDVal"); diff --git a/lib/models/collection.dart b/lib/models/collection.dart index 75c8b07f7..4995d8313 100644 --- a/lib/models/collection.dart +++ b/lib/models/collection.dart @@ -85,7 +85,7 @@ class Collection { String mMdEncodedJson, int mMdVersion, }) { - Collection result = Collection( + final Collection result = Collection( id ?? this.id, owner ?? this.owner, encryptedKey ?? this.encryptedKey, diff --git a/lib/models/file.dart b/lib/models/file.dart index 931aa9839..139735f9b 100644 --- a/lib/models/file.dart +++ b/lib/models/file.dart @@ -61,7 +61,7 @@ class File extends EnteFile { File(); static Future fromAsset(String pathName, AssetEntity asset) async { - File file = File(); + final File file = File(); file.localID = asset.id; file.title = asset.title; file.deviceFolder = pathName; diff --git a/lib/models/selected_files.dart b/lib/models/selected_files.dart index c64b14f33..3021ab765 100644 --- a/lib/models/selected_files.dart +++ b/lib/models/selected_files.dart @@ -9,7 +9,7 @@ class SelectedFiles extends ChangeNotifier { // To handle the cases, where the file might have changed due to upload // or any other update, using file.generatedID to track if this file was already // selected or not - File alreadySelected = files.firstWhere( + final File alreadySelected = files.firstWhere( (element) => element.generatedID == file.generatedID, orElse: () => null, ); @@ -24,7 +24,7 @@ class SelectedFiles extends ChangeNotifier { } bool isFileSelected(File file) { - File alreadySelected = files.firstWhere( + final File alreadySelected = files.firstWhere( (element) => element.generatedID == file.generatedID, orElse: () => null, ); @@ -32,7 +32,7 @@ class SelectedFiles extends ChangeNotifier { } bool isPartOfLastSection(File file) { - File alreadySelected = lastSelections.firstWhere( + final File alreadySelected = lastSelections.firstWhere( (element) => element.generatedID == file.generatedID, orElse: () => null, ); diff --git a/lib/models/subscription.dart b/lib/models/subscription.dart index 74cbe2aff..976b7af37 100644 --- a/lib/models/subscription.dart +++ b/lib/models/subscription.dart @@ -144,7 +144,7 @@ class Attributes { } Map toJson() { - var map = {}; + final map = {}; map["isCancelled"] = isCancelled; map["customerID"] = customerID; return map; diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index b6febdb76..707b06b3d 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -308,7 +308,7 @@ class CollectionsService { // read the existing magic metadata and apply new updates to existing data // current update is simple replace. This will be enhanced in the future, // as required. - Map jsonToUpdate = + final Map jsonToUpdate = jsonDecode(collection.mMdEncodedJson ?? '{}'); newMetadataUpdate.forEach((key, value) { jsonToUpdate[key] = value; @@ -325,7 +325,7 @@ class CollectionsService { ); // for required field, the json validator on golang doesn't treat 0 as valid // value. Instead of changing version to ptr, decided to start version with 1. - int currentVersion = max(collection.mMdVersion, 1); + final int currentVersion = max(collection.mMdVersion, 1); final params = UpdateMagicMetadataRequest( id: collection.id, magicMetadata: MetadataRequest( diff --git a/lib/services/deduplication_service.dart b/lib/services/deduplication_service.dart index 2dd8d302b..5c843b091 100644 --- a/lib/services/deduplication_service.dart +++ b/lib/services/deduplication_service.dart @@ -18,7 +18,7 @@ class DeduplicationService { Future> getDuplicateFiles() async { try { - DuplicateFilesResponse dupes = await _fetchDuplicateFileIDs(); + final DuplicateFilesResponse dupes = await _fetchDuplicateFileIDs(); final ids = []; for (final dupe in dupes.duplicates) { ids.addAll(dupe.fileIDs); diff --git a/lib/services/favorites_service.dart b/lib/services/favorites_service.dart index 5c5307ea2..e5d25e026 100644 --- a/lib/services/favorites_service.dart +++ b/lib/services/favorites_service.dart @@ -53,7 +53,7 @@ class FavoritesService { Future removeFromFavorites(File file) async { final collectionID = await _getOrCreateFavoriteCollectionID(); - var fileID = file.uploadedFileID; + final fileID = file.uploadedFileID; if (fileID == null) { // Do nothing, ignore } else { diff --git a/lib/services/feature_flag_service.dart b/lib/services/feature_flag_service.dart index 346a0ee30..a1ff5ca94 100644 --- a/lib/services/feature_flag_service.dart +++ b/lib/services/feature_flag_service.dart @@ -94,7 +94,7 @@ class FeatureFlagService { } bool _isInternalUserOrDebugBuild() { - String email = Configuration.instance.getEmail(); + final String email = Configuration.instance.getEmail(); return (email != null && email.endsWith("@ente.io")) || kDebugMode; } diff --git a/lib/services/file_magic_service.dart b/lib/services/file_magic_service.dart index a03fe71fb..0943e2591 100644 --- a/lib/services/file_magic_service.dart +++ b/lib/services/file_magic_service.dart @@ -30,7 +30,7 @@ class FileMagicService { FileMagicService._privateConstructor(); Future changeVisibility(List files, int visibility) async { - Map update = {kMagicKeyVisibility: visibility}; + final Map update = {kMagicKeyVisibility: visibility}; await _updateMagicData(files, update); if (visibility == kVisibilityVisible) { // Force reload home gallery to pull in the now unarchived files @@ -62,7 +62,7 @@ class FileMagicService { // read the existing magic metadata and apply new updates to existing data // current update is simple replace. This will be enhanced in the future, // as required. - Map jsonToUpdate = jsonDecode(file.pubMmdEncodedJson); + final Map jsonToUpdate = jsonDecode(file.pubMmdEncodedJson); newMetadataUpdate.forEach((key, value) { jsonToUpdate[key] = value; }); @@ -132,7 +132,7 @@ class FileMagicService { // read the existing magic metadata and apply new updates to existing data // current update is simple replace. This will be enhanced in the future, // as required. - Map jsonToUpdate = jsonDecode(file.mMdEncodedJson); + final Map jsonToUpdate = jsonDecode(file.mMdEncodedJson); newMetadataUpdate.forEach((key, value) { jsonToUpdate[key] = value; }); @@ -224,7 +224,7 @@ class MetadataRequest { } Map toJson() { - var map = {}; + final map = {}; map['version'] = version; map['count'] = count; map['data'] = data; diff --git a/lib/services/file_migration_service.dart b/lib/services/file_migration_service.dart index 5b64d4fe5..f71ac986d 100644 --- a/lib/services/file_migration_service.dart +++ b/lib/services/file_migration_service.dart @@ -63,14 +63,14 @@ class FileMigrationService { } // migration only needs to run if Android API Level is 29 or higher final int version = int.parse(await PhotoManager.systemVersion()); - bool isMigrationRequired = version >= 29; + final bool isMigrationRequired = version >= 29; if (isMigrationRequired) { await _importLocalFilesForMigration(); final sTime = DateTime.now().microsecondsSinceEpoch; bool hasData = true; const int limitInBatch = 100; while (hasData) { - var localIDsToProcess = await _filesMigrationDB + final localIDsToProcess = await _filesMigrationDB .getLocalIDsForPotentialReUpload(limitInBatch); if (localIDsToProcess.isEmpty) { hasData = false; @@ -91,15 +91,15 @@ class FileMigrationService { List localIDsToProcess, ) async { _logger.info("files to process ${localIDsToProcess.length}"); - var localIDsWithLocation = []; + final localIDsWithLocation = []; for (var localID in localIDsToProcess) { bool hasLocation = false; try { - var assetEntity = await AssetEntity.fromId(localID); + final assetEntity = await AssetEntity.fromId(localID); if (assetEntity == null) { continue; } - var latLng = await assetEntity.latlngAsync(); + final latLng = await assetEntity.latlngAsync(); if ((latLng.longitude ?? 0.0) != 0.0 || (latLng.longitude ?? 0.0) != 0.0) { _logger.finest( @@ -125,7 +125,7 @@ class FileMigrationService { } final sTime = DateTime.now().microsecondsSinceEpoch; _logger.info('importing files without location info'); - var fileLocalIDs = await _filesDB.getLocalFilesBackedUpWithoutLocation(); + final fileLocalIDs = await _filesDB.getLocalFilesBackedUpWithoutLocation(); await _filesMigrationDB.insertMultiple(fileLocalIDs); final eTime = DateTime.now().microsecondsSinceEpoch; final d = Duration(microseconds: eTime - sTime); diff --git a/lib/services/local_sync_service.dart b/lib/services/local_sync_service.dart index 9bdcea8a8..9960635c6 100644 --- a/lib/services/local_sync_service.dart +++ b/lib/services/local_sync_service.dart @@ -162,7 +162,7 @@ class LocalSyncService { if (_prefs.containsKey(kEditedFileIDsKey)) { return _prefs.getStringList(kEditedFileIDsKey); } else { - List editedIDs = []; + final List editedIDs = []; return editedIDs; } } @@ -177,7 +177,7 @@ class LocalSyncService { if (_prefs.containsKey(kDownloadedFileIDsKey)) { return _prefs.getStringList(kDownloadedFileIDsKey); } else { - List downloadedIDs = []; + final List downloadedIDs = []; return downloadedIDs; } } @@ -192,7 +192,7 @@ class LocalSyncService { if (_prefs.containsKey(kInvalidFileIDsKey)) { return _prefs.getStringList(kInvalidFileIDsKey); } else { - List invalidIDs = []; + final List invalidIDs = []; return invalidIDs; } } @@ -273,9 +273,9 @@ class LocalSyncService { ); try { if (Platform.isIOS) { - var assetEntity = await AssetEntity.fromId(file.localID); + final assetEntity = await AssetEntity.fromId(file.localID); if (assetEntity != null) { - var isLocallyAvailable = + final isLocallyAvailable = await assetEntity.isLocallyAvailable(isOrigin: true); _logger.info( 're-upload asset ${file.toString()} with localAvailableFlag ' diff --git a/lib/services/remote_sync_service.dart b/lib/services/remote_sync_service.dart index 37659749e..23fad5dc6 100644 --- a/lib/services/remote_sync_service.dart +++ b/lib/services/remote_sync_service.dart @@ -265,7 +265,7 @@ class RemoteSyncService { _logger.info(editedFiles.length.toString() + " files edited."); _completedUploads = 0; - int toBeUploaded = + final int toBeUploaded = filesToBeUploaded.length + updatedFileIDs.length + editedFiles.length; if (toBeUploaded > 0) { @@ -374,8 +374,8 @@ class RemoteSyncService { localButUpdatedOnRemote = 0, localButAddedToNewCollectionOnRemote = 0; bool hasAnyCreationTimeChanged = false; - List toBeInserted = []; - int userID = Configuration.instance.getUserID(); + final List toBeInserted = []; + final int userID = Configuration.instance.getUserID(); for (File file in diff) { final existingFiles = file.deviceFolder == null ? null @@ -420,7 +420,7 @@ class RemoteSyncService { } else { file.localID = null; } - bool wasUploadedOnAPreviousInstallation = + final bool wasUploadedOnAPreviousInstallation = existingFiles.length == 1 && existingFiles[0].collectionID == null; if (wasUploadedOnAPreviousInstallation) { file.generatedID = existingFiles[0].generatedID; diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index b6529300e..cc621dc4a 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -806,7 +806,7 @@ class UserService { Future getPaymentToken() async { try { - var response = await _dio.get( + final response = await _dio.get( "${_config.getHttpEndpoint()}/users/payment-token", options: Options( headers: { @@ -827,7 +827,7 @@ class UserService { Future getFamiliesToken() async { try { - var response = await _dio.get( + final response = await _dio.get( "${_config.getHttpEndpoint()}/users/families-token", options: Options( headers: { diff --git a/lib/ui/account/delete_account_page.dart b/lib/ui/account/delete_account_page.dart index 129e13c59..c79134e78 100644 --- a/lib/ui/account/delete_account_page.dart +++ b/lib/ui/account/delete_account_page.dart @@ -145,7 +145,7 @@ class DeleteAccountPage extends StatelessWidget { DeleteChallengeResponse response, ) async { AppLock.of(context).setEnabled(false); - String reason = "Please authenticate to initiate account deletion"; + const String reason = "Please authenticate to initiate account deletion"; final result = await requestAuthentication(reason); AppLock.of(context).setEnabled( Configuration.instance.shouldShowLockScreen(), @@ -177,7 +177,7 @@ class DeleteAccountPage extends StatelessWidget { } Future _requestEmailForDeletion(BuildContext context) async { - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: const Text( "Delete account", style: TextStyle( diff --git a/lib/ui/account/password_reentry_page.dart b/lib/ui/account/password_reentry_page.dart index ad89437d0..9868bfd73 100644 --- a/lib/ui/account/password_reentry_page.dart +++ b/lib/ui/account/password_reentry_page.dart @@ -79,7 +79,7 @@ class _PasswordReentryPageState extends State { _logger.severe("Password verification failed", e, s); await dialog.hide(); - var dialogUserChoice = await showChoiceDialog( + final dialogUserChoice = await showChoiceDialog( context, "Incorrect password", "Please try again", diff --git a/lib/ui/account/recovery_key_page.dart b/lib/ui/account/recovery_key_page.dart index 6cffc36de..8272d8d9c 100644 --- a/lib/ui/account/recovery_key_page.dart +++ b/lib/ui/account/recovery_key_page.dart @@ -186,7 +186,7 @@ class _RecoveryKeyPageState extends State { } List _saveOptions(BuildContext context, String recoveryKey) { - List childrens = []; + final List childrens = []; if (!_hasTriedToSave) { childrens.add( ElevatedButton( diff --git a/lib/ui/account/sessions_page.dart b/lib/ui/account/sessions_page.dart index b78cd8ce2..f573ceb7c 100644 --- a/lib/ui/account/sessions_page.dart +++ b/lib/ui/account/sessions_page.dart @@ -41,7 +41,7 @@ class _SessionsPageState extends State { if (_sessions == null) { return const Center(child: EnteLoadingWidget()); } - List rows = []; + final List rows = []; rows.add(const Padding(padding: EdgeInsets.all(4))); for (final session in _sessions.sessions) { rows.add(_getSessionWidget(session)); @@ -163,7 +163,7 @@ class _SessionsPageState extends State { ), ); } - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: const Text("Terminate session?"), content: text, actions: [ diff --git a/lib/ui/account/two_factor_setup_page.dart b/lib/ui/account/two_factor_setup_page.dart index ca63c8590..3f67a72ee 100644 --- a/lib/ui/account/two_factor_setup_page.dart +++ b/lib/ui/account/two_factor_setup_page.dart @@ -116,7 +116,7 @@ class _TwoFactorSetupPageState extends State Divider( height: 1, thickness: 1, - color: Theme.of(context).accentColor, + color: Theme.of(context).colorScheme.secondary, ), _getVerificationWidget(), ], @@ -126,7 +126,7 @@ class _TwoFactorSetupPageState extends State } Widget _getSecretCode() { - Color textColor = Theme.of(context).colorScheme.onSurface; + final Color textColor = Theme.of(context).colorScheme.onSurface; return GestureDetector( onTap: () async { await Clipboard.setData(ClipboardData(text: widget.secretCode)); diff --git a/lib/ui/collections/collection_item_widget.dart b/lib/ui/collections/collection_item_widget.dart index 444ad9080..482e7df80 100644 --- a/lib/ui/collections/collection_item_widget.dart +++ b/lib/ui/collections/collection_item_widget.dart @@ -19,11 +19,11 @@ class CollectionItem extends StatelessWidget { Widget build(BuildContext context) { const double horizontalPaddingOfGridRow = 16; const double crossAxisSpacingOfGrid = 9; - Size size = MediaQuery.of(context).size; - int albumsCountInOneRow = max(size.width ~/ 220.0, 2); - double totalWhiteSpaceOfRow = (horizontalPaddingOfGridRow * 2) + + final Size size = MediaQuery.of(context).size; + final int albumsCountInOneRow = max(size.width ~/ 220.0, 2); + final double totalWhiteSpaceOfRow = (horizontalPaddingOfGridRow * 2) + (albumsCountInOneRow - 1) * crossAxisSpacingOfGrid; - TextStyle albumTitleTextStyle = + final TextStyle albumTitleTextStyle = Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 14); final double sideOfThumbnail = (size.width / albumsCountInOneRow) - (totalWhiteSpaceOfRow / albumsCountInOneRow); diff --git a/lib/ui/collections/remote_collections_grid_view_widget.dart b/lib/ui/collections/remote_collections_grid_view_widget.dart index 52e8a0c60..780160079 100644 --- a/lib/ui/collections/remote_collections_grid_view_widget.dart +++ b/lib/ui/collections/remote_collections_grid_view_widget.dart @@ -17,8 +17,8 @@ class RemoteCollectionsGridViewWidget extends StatelessWidget { Widget build(BuildContext context) { const double horizontalPaddingOfGridRow = 16; const double crossAxisSpacingOfGrid = 9; - Size size = MediaQuery.of(context).size; - int albumsCountInOneRow = max(size.width ~/ 220.0, 2); + final Size size = MediaQuery.of(context).size; + final int albumsCountInOneRow = max(size.width ~/ 220.0, 2); final double sideOfThumbnail = (size.width / albumsCountInOneRow) - horizontalPaddingOfGridRow - ((crossAxisSpacingOfGrid / 2) * (albumsCountInOneRow - 1)); diff --git a/lib/ui/common/dialogs.dart b/lib/ui/common/dialogs.dart index d20b69c8d..e26b5b492 100644 --- a/lib/ui/common/dialogs.dart +++ b/lib/ui/common/dialogs.dart @@ -19,7 +19,7 @@ Future showChoiceDialog( Color secondActionColor, ActionType actionType = ActionType.confirm, }) { - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: Text( title, style: TextStyle( diff --git a/lib/ui/create_collection_page.dart b/lib/ui/create_collection_page.dart index 56af9a2b2..e37a9ed65 100644 --- a/lib/ui/create_collection_page.dart +++ b/lib/ui/create_collection_page.dart @@ -202,7 +202,7 @@ class _CreateCollectionPageState extends State { } void _showNameAlbumDialog() async { - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: const Text("Album title"), content: TextFormField( decoration: const InputDecoration( @@ -284,7 +284,7 @@ class _CreateCollectionPageState extends State { final dialog = createProgressDialog(context, "Moving files to album..."); await dialog.show(); try { - int fromCollectionID = widget.selectedFiles.files?.first?.collectionID; + final int fromCollectionID = widget.selectedFiles.files?.first?.collectionID; await CollectionsService.instance.move( toCollectionID, fromCollectionID, diff --git a/lib/ui/grant_permissions_widget.dart b/lib/ui/grant_permissions_widget.dart index 283a3faea..93cb7cc5c 100644 --- a/lib/ui/grant_permissions_widget.dart +++ b/lib/ui/grant_permissions_widget.dart @@ -94,7 +94,7 @@ class GrantPermissionsWidget extends StatelessWidget { state == PermissionState.limited) { await SyncService.instance.onPermissionGranted(state); } else if (state == PermissionState.denied) { - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: const Text("Please grant permissions"), content: const Text( "ente can encrypt and preserve files only if you grant access to them", diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 14c964801..3040e5819 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -123,7 +123,7 @@ class _HomeWidgetState extends State { }); _triggerLogoutEvent = Bus.instance.on().listen((event) async { - AlertDialog alert = AlertDialog( + final AlertDialog alert = AlertDialog( title: const Text("Session expired"), content: const Text("Please login again"), actions: [ @@ -344,7 +344,7 @@ class _HomeWidgetState extends State { Future _initDeepLinks() async { // Platform messages may fail, so we use a try/catch PlatformException. try { - String initialLink = await getInitialLink(); + final String initialLink = await getInitialLink(); // Parse the link and warn the user, if it is not correct, // but keep in mind it could be `null`. if (initialLink != null) { @@ -609,7 +609,7 @@ class _HomeBottomNavigationBarState extends State { @override Widget build(BuildContext context) { - bool filesAreSelected = widget.selectedFiles.files.isNotEmpty; + final bool filesAreSelected = widget.selectedFiles.files.isNotEmpty; return AnimatedContainer( duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, diff --git a/lib/ui/huge_listview/draggable_scrollbar.dart b/lib/ui/huge_listview/draggable_scrollbar.dart index b5e55570b..846968db2 100644 --- a/lib/ui/huge_listview/draggable_scrollbar.dart +++ b/lib/ui/huge_listview/draggable_scrollbar.dart @@ -175,7 +175,7 @@ class DraggableScrollbarState extends State if (isDragging && details.delta.dy != 0) { thumbOffset += details.delta.dy; thumbOffset = thumbOffset.clamp(thumbMin, thumbMax); - double position = thumbOffset / (thumbMax - thumbMin); + final double position = thumbOffset / (thumbMax - thumbMin); widget.onChange?.call(position); } }); diff --git a/lib/ui/huge_listview/huge_listview.dart b/lib/ui/huge_listview/huge_listview.dart index 51f93bbe8..3bb6c91d8 100644 --- a/lib/ui/huge_listview/huge_listview.dart +++ b/lib/ui/huge_listview/huge_listview.dart @@ -97,7 +97,7 @@ class HugeListViewState extends State> { } void _sendScroll() { - int current = _currentFirst(); + final int current = _currentFirst(); widget.firstShown?.call(current); scrollKey.currentState?.setPosition(current / widget.totalCount, current); } diff --git a/lib/ui/huge_listview/lazy_loading_gallery.dart b/lib/ui/huge_listview/lazy_loading_gallery.dart index bffbc8c26..57287f143 100644 --- a/lib/ui/huge_listview/lazy_loading_gallery.dart +++ b/lib/ui/huge_listview/lazy_loading_gallery.dart @@ -71,7 +71,7 @@ class _LazyLoadingGalleryState extends State { _currentIndexSubscription = widget.currentIndexStream.listen((currentIndex) { - bool shouldRender = (currentIndex - widget.index).abs() < + final bool shouldRender = (currentIndex - widget.index).abs() < kNumberOfDaysToRenderBeforeAndAfter; if (mounted && shouldRender != _shouldRender) { setState(() { @@ -163,7 +163,7 @@ class _LazyLoadingGalleryState extends State { } Widget _getGallery() { - List childGalleries = []; + final List childGalleries = []; for (int index = 0; index < _files.length; index += kSubGalleryItemLimit) { childGalleries.add( LazyLoadingGridView( diff --git a/lib/ui/memories_widget.dart b/lib/ui/memories_widget.dart index f269cf900..620343f8b 100644 --- a/lib/ui/memories_widget.dart +++ b/lib/ui/memories_widget.dart @@ -66,9 +66,9 @@ class MemoriesWidget extends StatelessWidget { } bool _areMemoriesFromSameYear(Memory first, Memory second) { - var firstDate = + final firstDate = DateTime.fromMicrosecondsSinceEpoch(first.file.creationTime); - var secondDate = + final secondDate = DateTime.fromMicrosecondsSinceEpoch(second.file.creationTime); return firstDate.year == secondDate.year; } diff --git a/lib/ui/nav_bar.dart b/lib/ui/nav_bar.dart index 5156a3a1e..90f92964f 100644 --- a/lib/ui/nav_bar.dart +++ b/lib/ui/nav_bar.dart @@ -321,7 +321,7 @@ class _ButtonState extends State