Bladeren bron

Merge pull request #518 from ente-io/migrate-to-null-safety

Migrate to null safety
Ashil 2 jaren geleden
bovenliggende
commit
19123c1957

+ 3 - 5
lib/core/cache/image_cache.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:io' as io;
 
 import 'package:photos/core/cache/lru_map.dart';
@@ -7,11 +5,11 @@ import 'package:photos/core/cache/lru_map.dart';
 class FileLruCache {
   static final LRUMap<String, io.File> _map = LRUMap(25);
 
-  static io.File get(String key) {
+  static io.File? get(String key) {
     return _map.get(key);
   }
 
-  static void put(String key, io.File imageData) {
-    _map.put(key, imageData);
+  static void put(String key, io.File value) {
+    _map.put(key, value);
   }
 }

+ 5 - 7
lib/core/cache/lru_map.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:collection';
 
 typedef EvictionHandler<K, V> = Function(K key, V value);
@@ -7,12 +5,12 @@ typedef EvictionHandler<K, V> = Function(K key, V value);
 class LRUMap<K, V> {
   final LinkedHashMap<K, V> _map = LinkedHashMap<K, V>();
   final int _maxSize;
-  final EvictionHandler<K, V> _handler;
+  final EvictionHandler<K, V?>? _handler;
 
   LRUMap(this._maxSize, [this._handler]);
 
-  V get(K key) {
-    final V value = _map.remove(key);
+  V? get(K key) {
+    final V? value = _map.remove(key);
     if (value != null) {
       _map[key] = value;
     }
@@ -24,9 +22,9 @@ class LRUMap<K, V> {
     _map[key] = value;
     if (_map.length > _maxSize) {
       final K evictedKey = _map.keys.first;
-      final V evictedValue = _map.remove(evictedKey);
+      final V? evictedValue = _map.remove(evictedKey);
       if (_handler != null) {
-        _handler(evictedKey, evictedValue);
+        _handler!(evictedKey, evictedValue);
       }
     }
   }

+ 1 - 3
lib/core/network.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:io';
 import 'package:dio/dio.dart';
 import 'package:fk_user_agent/fk_user_agent.dart';
@@ -9,7 +7,7 @@ import 'package:uuid/uuid.dart';
 int kConnectTimeout = 15000;
 
 class Network {
-  Dio _dio;
+  late Dio _dio;
 
   Future<void> init() async {
     await FkUserAgent.init();

+ 5 - 12
lib/events/sync_status_update_event.dart

@@ -1,15 +1,13 @@
-// @dart=2.9
-
 import 'package:photos/events/event.dart';
 
 class SyncStatusUpdate extends Event {
-  final int completed;
-  final int total;
-  final bool wasStopped;
   final SyncStatus status;
+  final int? completed;
+  final int? total;
+  final bool wasStopped;
   final String reason;
-  final Error error;
-  int timestamp;
+  final Error? error;
+  late int timestamp;
 
   SyncStatusUpdate(
     this.status, {
@@ -21,11 +19,6 @@ class SyncStatusUpdate extends Event {
   }) {
     timestamp = DateTime.now().microsecondsSinceEpoch;
   }
-
-  @override
-  String toString() {
-    return 'SyncStatusUpdate(completed: $completed, total: $total, wasStopped: $wasStopped, status: $status, reason: $reason, error: $error)';
-  }
 }
 
 enum SyncStatus {

+ 0 - 7
lib/events/tab_changed_event.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'package:photos/events/event.dart';
 
 class TabChangedEvent extends Event {
@@ -10,11 +8,6 @@ class TabChangedEvent extends Event {
     this.selectedIndex,
     this.source,
   );
-
-  @override
-  String toString() {
-    return 'TabChangedEvent{selectedIndex: $selectedIndex, source: $source}';
-  }
 }
 
 enum TabChangedEventSource {

+ 8 - 8
lib/models/encryption_result.dart

@@ -1,15 +1,15 @@
 import 'dart:typed_data';
 
 class EncryptionResult {
-  final Uint8List encryptedData;
-  final Uint8List key;
-  final Uint8List header;
-  final Uint8List nonce;
+  final Uint8List? encryptedData;
+  final Uint8List? key;
+  final Uint8List? header;
+  final Uint8List? nonce;
 
   EncryptionResult({
-    required this.encryptedData,
-    required this.key,
-    required this.header,
-    required this.nonce,
+    this.encryptedData,
+    this.key,
+    this.header,
+    this.nonce,
   });
 }

+ 0 - 2
lib/services/app_lifecycle_service.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'package:logging/logging.dart';
 
 class AppLifecycleService {

+ 2 - 4
lib/utils/crypto_util.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:io' as io;
 import 'dart:typed_data';
 
@@ -201,7 +199,7 @@ class CryptoUtil {
 
   static Uint8List decryptSync(
     Uint8List cipher,
-    Uint8List key,
+    Uint8List? key,
     Uint8List nonce,
   ) {
     assert(key != null, "key can not be null");
@@ -237,7 +235,7 @@ class CryptoUtil {
   static Future<EncryptionResult> encryptFile(
     String sourceFilePath,
     String destinationFilePath, {
-    Uint8List key,
+    Uint8List? key,
   }) {
     final args = <String, dynamic>{};
     args["sourceFilePath"] = sourceFilePath;