浏览代码

Fix moar linter warnings

vishnukvmd 4 年之前
父节点
当前提交
eb9de99730

+ 1 - 1
lib/core/cache/image_cache.dart

@@ -4,7 +4,7 @@ import 'package:photos/core/cache/lru_map.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 
 
 class FileLruCache {
 class FileLruCache {
-  static LRUMap<String, io.File> _map = LRUMap(25);
+  static final LRUMap<String, io.File> _map = LRUMap(25);
 
 
   static io.File get(File file) {
   static io.File get(File file) {
     return _map.get(file.tag());
     return _map.get(file.tag());

+ 2 - 2
lib/core/cache/lru_map.dart

@@ -1,9 +1,9 @@
 import 'dart:collection';
 import 'dart:collection';
 
 
-typedef EvictionHandler<K, V>(K key, V value);
+typedef EvictionHandler<K, V> = Function(K key, V value);
 
 
 class LRUMap<K, V> {
 class LRUMap<K, V> {
-  final LinkedHashMap<K, V> _map = new LinkedHashMap<K, V>();
+  final LinkedHashMap<K, V> _map = LinkedHashMap<K, V>();
   final int _maxSize;
   final int _maxSize;
   final EvictionHandler<K, V> _handler;
   final EvictionHandler<K, V> _handler;
 
 

+ 1 - 1
lib/core/cache/thumbnail_cache.dart

@@ -5,7 +5,7 @@ import 'package:photos/core/constants.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 
 
 class ThumbnailLruCache {
 class ThumbnailLruCache {
-  static LRUMap<String, Uint8List> _map = LRUMap(1000);
+  static final LRUMap<String, Uint8List> _map = LRUMap(1000);
 
 
   static Uint8List get(File photo, [int size]) {
   static Uint8List get(File photo, [int size]) {
     return _map.get(photo.generatedID.toString() +
     return _map.get(photo.generatedID.toString() +

+ 2 - 2
lib/db/collections_db.dart

@@ -126,7 +126,7 @@ class CollectionsDB {
   Future<List<Collection>> getAllCollections() async {
   Future<List<Collection>> getAllCollections() async {
     final db = await instance.database;
     final db = await instance.database;
     final rows = await db.query(table);
     final rows = await db.query(table);
-    final collections = List<Collection>();
+    final collections = <Collection>[];
     for (final row in rows) {
     for (final row in rows) {
       collections.add(_convertToCollection(row));
       collections.add(_convertToCollection(row));
     }
     }
@@ -157,7 +157,7 @@ class CollectionsDB {
   }
   }
 
 
   Map<String, dynamic> _getRowForCollection(Collection collection) {
   Map<String, dynamic> _getRowForCollection(Collection collection) {
-    var row = new Map<String, dynamic>();
+    var row = <String, dynamic>{};
     row[columnID] = collection.id;
     row[columnID] = collection.id;
     row[columnOwner] = collection.owner.toJson();
     row[columnOwner] = collection.owner.toJson();
     row[columnEncryptedKey] = collection.encryptedKey;
     row[columnEncryptedKey] = collection.encryptedKey;

+ 2 - 2
lib/db/memories_db.dart

@@ -69,14 +69,14 @@ class MemoriesDB {
   }
   }
 
 
   Map<String, dynamic> _getRowForSeenMemory(Memory memory, int timestamp) {
   Map<String, dynamic> _getRowForSeenMemory(Memory memory, int timestamp) {
-    var row = new Map<String, dynamic>();
+    var row = <String, dynamic>{};
     row[columnFileID] = memory.file.generatedID;
     row[columnFileID] = memory.file.generatedID;
     row[columnSeenTime] = timestamp;
     row[columnSeenTime] = timestamp;
     return row;
     return row;
   }
   }
 
 
   Map<int, int> _convertToSeenTimes(List<Map<String, dynamic>> rows) {
   Map<int, int> _convertToSeenTimes(List<Map<String, dynamic>> rows) {
-    final seenTimes = Map<int, int>();
+    final seenTimes = <int, int>{};
     for (final row in rows) {
     for (final row in rows) {
       seenTimes[row[columnFileID]] = int.parse(row[columnSeenTime]);
       seenTimes[row[columnFileID]] = int.parse(row[columnSeenTime]);
     }
     }

+ 2 - 2
lib/db/public_keys_db.dart

@@ -65,14 +65,14 @@ class PublicKeysDB {
   }
   }
 
 
   Map<String, dynamic> _getRow(PublicKey key) {
   Map<String, dynamic> _getRow(PublicKey key) {
-    var row = new Map<String, dynamic>();
+    var row = <String, dynamic>{};
     row[columnEmail] = key.email;
     row[columnEmail] = key.email;
     row[columnPublicKey] = key.publicKey;
     row[columnPublicKey] = key.publicKey;
     return row;
     return row;
   }
   }
 
 
   List<PublicKey> _convertRows(List<Map<String, dynamic>> rows) {
   List<PublicKey> _convertRows(List<Map<String, dynamic>> rows) {
-    final keys = List<PublicKey>();
+    final keys = <PublicKey>[];
     for (final row in rows) {
     for (final row in rows) {
       keys.add(PublicKey(row[columnEmail], row[columnPublicKey]));
       keys.add(PublicKey(row[columnEmail], row[columnPublicKey]));
     }
     }

+ 1 - 1
lib/db/upload_locks_db.dart

@@ -50,7 +50,7 @@ class UploadLocksDB {
 
 
   Future<void> acquireLock(String id, String owner, int time) async {
   Future<void> acquireLock(String id, String owner, int time) async {
     final db = await instance.database;
     final db = await instance.database;
-    final row = new Map<String, dynamic>();
+    final row = <String, dynamic>{};
     row[_columnID] = id;
     row[_columnID] = id;
     row[_columnOwner] = owner;
     row[_columnOwner] = owner;
     row[_columnTime] = time;
     row[_columnTime] = time;

+ 1 - 1
lib/events/sync_status_update_event.dart

@@ -17,7 +17,7 @@ class SyncStatusUpdate extends Event {
     this.reason = "",
     this.reason = "",
     this.error,
     this.error,
   }) {
   }) {
-    this.timestamp = DateTime.now().microsecondsSinceEpoch;
+    timestamp = DateTime.now().microsecondsSinceEpoch;
   }
   }
 
 
   @override
   @override

+ 2 - 2
lib/models/collection.dart

@@ -102,7 +102,7 @@ class Collection {
   factory Collection.fromMap(Map<String, dynamic> map) {
   factory Collection.fromMap(Map<String, dynamic> map) {
     if (map == null) return null;
     if (map == null) return null;
     final sharees = (map['sharees'] == null || map['sharees'].length == 0)
     final sharees = (map['sharees'] == null || map['sharees'].length == 0)
-        ? List<User>()
+        ? <User>[]
         : List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
         : List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
     return Collection(
     return Collection(
       map['id'],
       map['id'],
@@ -196,7 +196,7 @@ class CollectionAttributes {
   }
   }
 
 
   Map<String, dynamic> toMap() {
   Map<String, dynamic> toMap() {
-    final map = Map<String, dynamic>();
+    final map = <String, dynamic>{};
     if (encryptedPath != null) {
     if (encryptedPath != null) {
       map['encryptedPath'] = encryptedPath;
       map['encryptedPath'] = encryptedPath;
     }
     }

+ 1 - 1
lib/models/file.dart

@@ -81,7 +81,7 @@ class File {
   }
   }
 
 
   Map<String, dynamic> getMetadata() {
   Map<String, dynamic> getMetadata() {
-    final metadata = Map<String, dynamic>();
+    final metadata = <String, dynamic>{};
     metadata["localID"] = localID;
     metadata["localID"] = localID;
     metadata["title"] = title;
     metadata["title"] = title;
     metadata["deviceFolder"] = deviceFolder;
     metadata["deviceFolder"] = deviceFolder;

+ 3 - 3
lib/models/selected_files.dart

@@ -2,8 +2,8 @@ import 'package:flutter/foundation.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 
 
 class SelectedFiles extends ChangeNotifier {
 class SelectedFiles extends ChangeNotifier {
-  final files = Set<File>();
-  final lastSelections = Set<File>();
+  final files = <File>{};
+  final lastSelections = <File>{};
 
 
   void toggleSelection(File file) {
   void toggleSelection(File file) {
     if (files.contains(file)) {
     if (files.contains(file)) {
@@ -12,7 +12,7 @@ class SelectedFiles extends ChangeNotifier {
       files.add(file);
       files.add(file);
     }
     }
     lastSelections.clear();
     lastSelections.clear();
-     lastSelections.add(file);
+    lastSelections.add(file);
     notifyListeners();
     notifyListeners();
   }
   }
 
 

+ 7 - 10
lib/services/billing_service.dart

@@ -54,13 +54,10 @@ class BillingService {
   }
   }
 
 
   Future<BillingPlans> getBillingPlans() {
   Future<BillingPlans> getBillingPlans() {
-    if (_future == null) {
-      _future = _dio
-          .get(_config.getHttpEndpoint() + "/billing/plans")
-          .then((response) {
-        return BillingPlans.fromMap(response.data);
-      });
-    }
+    _future ??=
+        _dio.get(_config.getHttpEndpoint() + "/billing/plans").then((response) {
+      return BillingPlans.fromMap(response.data);
+    });
     return _future;
     return _future;
   }
   }
 
 
@@ -86,7 +83,7 @@ class BillingService {
       );
       );
       return Subscription.fromMap(response.data["subscription"]);
       return Subscription.fromMap(response.data["subscription"]);
     } catch (e) {
     } catch (e) {
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -104,7 +101,7 @@ class BillingService {
       return subscription;
       return subscription;
     } on DioError catch (e) {
     } on DioError catch (e) {
       _logger.severe(e);
       _logger.severe(e);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -124,7 +121,7 @@ class BillingService {
       );
       );
       return response.data["usage"];
       return response.data["usage"];
     } catch (e) {
     } catch (e) {
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 

+ 1 - 2
lib/services/local_sync_service.dart

@@ -26,7 +26,7 @@ class LocalSyncService {
   static const kDownloadedFileIDsKey = "downloaded_file_ids";
   static const kDownloadedFileIDsKey = "downloaded_file_ids";
   static const kInvalidFileIDsKey = "invalid_file_ids";
   static const kInvalidFileIDsKey = "invalid_file_ids";
 
 
-  LocalSyncService._privateConstructor() {}
+  LocalSyncService._privateConstructor();
 
 
   static final LocalSyncService instance =
   static final LocalSyncService instance =
       LocalSyncService._privateConstructor();
       LocalSyncService._privateConstructor();
@@ -41,7 +41,6 @@ class LocalSyncService {
     PhotoManager.addChangeCallback((value) {
     PhotoManager.addChangeCallback((value) {
       _logger.info("Something changed on disk");
       _logger.info("Something changed on disk");
       callback();
       callback();
-
     });
     });
     PhotoManager.startChangeNotify();
     PhotoManager.startChangeNotify();
   }
   }

+ 2 - 2
lib/services/sync_service.dart

@@ -122,7 +122,7 @@ class SyncService {
       }
       }
       _logger.severe("backup failed", e, s);
       _logger.severe("backup failed", e, s);
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.error));
       Bus.instance.fire(SyncStatusUpdate(SyncStatus.error));
-      throw e;
+      rethrow;
     } finally {
     } finally {
       _existingSync.complete(successful);
       _existingSync.complete(successful);
       _existingSync = null;
       _existingSync = null;
@@ -212,7 +212,7 @@ class SyncService {
       return response.data["size"];
       return response.data["size"];
     } catch (e) {
     } catch (e) {
       _logger.severe(e);
       _logger.severe(e);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 

+ 9 - 9
lib/services/user_service.dart

@@ -106,7 +106,7 @@ class UserService {
         await dialog.hide();
         await dialog.hide();
         Navigator.of(context).popUntil((route) => route.isFirst);
         Navigator.of(context).popUntil((route) => route.isFirst);
       } else {
       } else {
-        throw new Exception("log out action failed");
+        throw Exception("log out action failed");
       }
       }
     } catch (e) {
     } catch (e) {
       _logger.severe(e);
       _logger.severe(e);
@@ -129,7 +129,7 @@ class UserService {
       await dialog.hide();
       await dialog.hide();
       if (response != null && response.statusCode == 200) {
       if (response != null && response.statusCode == 200) {
         showToast("email verification successful!");
         showToast("email verification successful!");
-        var page;
+        Widget page;
         final String twoFASessionID = response.data["twoFactorSessionID"];
         final String twoFASessionID = response.data["twoFactorSessionID"];
         if (twoFASessionID != null && twoFASessionID.isNotEmpty) {
         if (twoFASessionID != null && twoFASessionID.isNotEmpty) {
           page = TwoFactorAuthenticationPage(twoFASessionID);
           page = TwoFactorAuthenticationPage(twoFASessionID);
@@ -180,7 +180,7 @@ class UserService {
       await _config.setKeyAttributes(result.keyAttributes);
       await _config.setKeyAttributes(result.keyAttributes);
     } catch (e) {
     } catch (e) {
       _logger.severe(e);
       _logger.severe(e);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -205,7 +205,7 @@ class UserService {
       await _config.setKeyAttributes(keyAttributes);
       await _config.setKeyAttributes(keyAttributes);
     } catch (e) {
     } catch (e) {
       _logger.severe(e);
       _logger.severe(e);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -229,7 +229,7 @@ class UserService {
       await _config.setKeyAttributes(keyAttributes);
       await _config.setKeyAttributes(keyAttributes);
     } catch (e) {
     } catch (e) {
       _logger.severe(e);
       _logger.severe(e);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -417,13 +417,13 @@ class UserService {
     } catch (e, s) {
     } catch (e, s) {
       await dialog.hide();
       await dialog.hide();
       _logger.severe(e, s);
       _logger.severe(e, s);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
   Future<bool> enableTwoFactor(
   Future<bool> enableTwoFactor(
       BuildContext context, String secret, String code) async {
       BuildContext context, String secret, String code) async {
-    var recoveryKey;
+    Uint8List recoveryKey;
     try {
     try {
       recoveryKey = await getOrCreateRecoveryKey(context);
       recoveryKey = await getOrCreateRecoveryKey(context);
     } catch (e) {
     } catch (e) {
@@ -507,7 +507,7 @@ class UserService {
       return response.data["status"];
       return response.data["status"];
     } catch (e, s) {
     } catch (e, s) {
       _logger.severe(e, s);
       _logger.severe(e, s);
-      throw e;
+      rethrow;
     }
     }
   }
   }
 
 
@@ -524,7 +524,7 @@ class UserService {
       } catch (e, s) {
       } catch (e, s) {
         await dialog.hide();
         await dialog.hide();
         _logger.severe(e, s);
         _logger.severe(e, s);
-        throw e;
+        rethrow;
       }
       }
     }
     }
     final recoveryKey = _config.getRecoveryKey();
     final recoveryKey = _config.getRecoveryKey();