فهرست منبع

NullSafety: More migration and fixes

Neeraj Gupta 2 سال پیش
والد
کامیت
0a84f06b5a

+ 5 - 5
lib/core/error-reporting/super_logging.dart

@@ -239,7 +239,7 @@ class SuperLogging {
       extraLines = null;
     }
 
-    final str = (config?.prefix ?? '') + " " + rec.toPrettyString(extraLines);
+    final str = (config.prefix ?? '') + " " + rec.toPrettyString(extraLines);
 
     // write to stdout
     printLog(str);
@@ -304,7 +304,7 @@ class SuperLogging {
   }
 
   static void doSentryRetry(Error error) async {
-    await Future.delayed(config!.sentryRetryDelay);
+    await Future.delayed(config.sentryRetryDelay);
     sentryQueueControl.add(error);
   }
 
@@ -315,7 +315,7 @@ class SuperLogging {
   static bool fileIsEnabled = false;
 
   static Future<void> setupLogDir() async {
-    var dirPath = config!.logDirPath;
+    var dirPath = config.logDirPath;
 
     // choose [logDir]
     if (dirPath == null || dirPath.isEmpty) {
@@ -324,7 +324,7 @@ class SuperLogging {
     }
 
     // create [logDir]
-    final dir = Directory(dirPath!);
+    final dir = Directory(dirPath);
     await dir.create(recursive: true);
 
     final files = <File>[];
@@ -360,7 +360,7 @@ class SuperLogging {
       }
     }
 
-    logFile = File("$dirPath/${config!.dateFmt!.format(DateTime.now())}.txt");
+    logFile = File("$dirPath/${config.dateFmt!.format(DateTime.now())}.txt");
   }
 
   /// Current app version, obtained from package_info plugin.

+ 5 - 5
lib/db/files_db.dart

@@ -823,19 +823,19 @@ class FilesDB {
 
   Future<int> updateUploadedFile(
     String localID,
-    String title,
-    Location location,
+    String? title,
+    Location? location,
     int creationTime,
     int modificationTime,
-    int updationTime,
+    int? updationTime,
   ) async {
     final db = await instance.database;
     return await db.update(
       filesTable,
       {
         columnTitle: title,
-        columnLatitude: location.latitude,
-        columnLongitude: location.longitude,
+        columnLatitude: location?.latitude,
+        columnLongitude: location?.longitude,
         columnCreationTime: creationTime,
         columnModificationTime: modificationTime,
         columnUpdationTime: updationTime,

+ 1 - 3
lib/events/collection_updated_event.dart

@@ -1,9 +1,7 @@
-// @dart=2.9
-
 import 'package:photos/events/files_updated_event.dart';
 
 class CollectionUpdatedEvent extends FilesUpdatedEvent {
-  final int collectionID;
+  final int? collectionID;
 
   CollectionUpdatedEvent(this.collectionID, updatedFiles, source, {type})
       : super(

+ 0 - 2
lib/events/files_updated_event.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'package:photos/events/event.dart';
 import 'package:photos/models/file.dart';
 

+ 4 - 2
lib/models/collection.dart

@@ -10,8 +10,10 @@ class Collection {
   final String encryptedKey;
   final String? keyDecryptionNonce;
   final String? name;
-  final String encryptedName;
-  final String nameDecryptionNonce;
+  // encryptedName & nameDecryptionNonce will be null for collections
+  // created before we started encrypting collection name
+  final String? encryptedName;
+  final String? nameDecryptionNonce;
   final CollectionType type;
   final CollectionAttributes attributes;
   final List<User?>? sharees;

+ 2 - 2
lib/services/remote_sync_service.dart

@@ -721,10 +721,10 @@ class RemoteSyncService {
   }
 
   bool _shouldClearCache(File remoteFile, File existingFile) {
-    if (remoteFile.hash != null && existingFile?.hash != null) {
+    if (remoteFile.hash != null && existingFile.hash != null) {
       return remoteFile.hash != existingFile.hash;
     }
-    return remoteFile.updationTime != (existingFile?.updationTime ?? 0);
+    return remoteFile.updationTime != (existingFile.updationTime ?? 0);
   }
 
   bool _shouldReloadHomeGallery(File remoteFile, File existingFile) {

+ 1 - 1
lib/services/update_service.dart

@@ -85,7 +85,7 @@ class UpdateService {
         (now - lastNotificationShownTime) > (3 * microSecondsInDay);
     if (shouldUpdate &&
         hasBeen3DaysSinceLastNotification &&
-        _latestVersion.shouldNotify) {
+        _latestVersion!.shouldNotify) {
       NotificationService.instance.showNotification(
         "Update available",
         "Click to install our best version yet",

+ 5 - 7
lib/ui/account/delete_account_page.dart

@@ -1,5 +1,3 @@
-// @dart=2.9
-
 import 'dart:convert';
 
 import 'package:flutter/material.dart';
@@ -17,7 +15,7 @@ import 'package:photos/utils/email_util.dart';
 
 class DeleteAccountPage extends StatelessWidget {
   const DeleteAccountPage({
-    Key key,
+    Key? key,
   }) : super(key: key);
 
   @override
@@ -53,7 +51,7 @@ class DeleteAccountPage extends StatelessWidget {
                   "We'll be sorry to see you go. Are you facing some issue?",
                   style: Theme.of(context)
                       .textTheme
-                      .subtitle1
+                      .subtitle1!
                       .copyWith(color: colorScheme.textMuted),
                 ),
               ),
@@ -75,7 +73,7 @@ class DeleteAccountPage extends StatelessWidget {
                   ],
                   style: Theme.of(context)
                       .textTheme
-                      .subtitle1
+                      .subtitle1!
                       .copyWith(color: colorScheme.textMuted),
                 ),
               ),
@@ -145,9 +143,9 @@ class DeleteAccountPage extends StatelessWidget {
           final decryptChallenge = CryptoUtil.openSealSync(
             Sodium.base642bin(response.encryptedChallenge),
             Sodium.base642bin(
-              Configuration.instance.getKeyAttributes().publicKey,
+              Configuration.instance.getKeyAttributes()!.publicKey,
             ),
-            Configuration.instance.getSecretKey(),
+            Configuration.instance.getSecretKey()!,
           );
           final challengeResponseStr = utf8.decode(decryptChallenge);
           await UserService.instance

+ 1 - 1
lib/ui/home_widget.dart

@@ -166,7 +166,7 @@ class _HomeWidgetState extends State<HomeWidget> {
             context: context,
             builder: (BuildContext context) {
               return AppUpdateDialog(
-                UpdateService.instance.getLatestVersionInfo()!,
+                UpdateService.instance.getLatestVersionInfo(),
               );
             },
             barrierColor: Colors.black.withOpacity(0.85),

+ 1 - 1
lib/ui/sharing/add_partipant_page.dart

@@ -313,7 +313,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
     }
     for (final c in CollectionsService.instance.getActiveCollections()) {
       if (c.owner?.id == ownerID) {
-        for (final User? u in c?.sharees ?? []) {
+        for (final User? u in c.sharees ?? []) {
           if (u != null && u.id != null && !existingUserIDs.contains(u.id)) {
             existingUserIDs.add(u.id!);
             suggestedUsers.add(u);

+ 1 - 1
lib/ui/viewer/file/collections_list_of_file_widget.dart

@@ -30,7 +30,7 @@ class CollectionsListOfFileWidget extends StatelessWidget {
           for (var collectionID in collectionIDs) {
             final c =
                 CollectionsService.instance.getCollectionByID(collectionID);
-            collections.add(c);
+            collections.add(c!);
           }
           return ListView.builder(
             itemCount: collections.length,

+ 2 - 2
lib/ui/viewer/file/file_caption_widget.dart

@@ -81,7 +81,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
   @override
   void dispose() {
     if (editedCaption != null) {
-      editFileCaption(null, widget.file, editedCaption);
+      editFileCaption(null, widget.file, editedCaption!);
     }
     _textController.dispose();
     _focusNode.removeListener(_focusNodeListener);
@@ -145,7 +145,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
   Future<void> _onDoneClick(BuildContext context) async {
     if (editedCaption != null) {
       final isSuccesful =
-          await editFileCaption(context, widget.file, editedCaption);
+          await editFileCaption(context, widget.file, editedCaption!);
       if (isSuccesful) {
         if (mounted) {
           Navigator.pop(context);