From ee3ca77f72a12d3a305c37def9c46db061fa7e06 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 20 Sep 2022 11:42:35 +0530 Subject: [PATCH] migrated collection.dart to null safety --- lib/models/collection.dart | 84 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/lib/models/collection.dart b/lib/models/collection.dart index 1930180c4..015a4f20b 100644 --- a/lib/models/collection.dart +++ b/lib/models/collection.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:convert'; import 'dart:core'; @@ -7,21 +5,21 @@ import 'package:photos/models/magic_metadata.dart'; class Collection { final int id; - final User owner; + final User? owner; final String encryptedKey; - final String keyDecryptionNonce; + final String? keyDecryptionNonce; final String name; final String encryptedName; final String nameDecryptionNonce; final CollectionType type; - final CollectionAttributes attributes; - final List sharees; - final List publicURLs; + final CollectionAttributes? attributes; + final List? sharees; + final List? publicURLs; final int updationTime; final bool isDeleted; - String mMdEncodedJson; + String? mMdEncodedJson; int mMdVersion = 0; - CollectionMagicMetadata _mmd; + CollectionMagicMetadata? _mmd; CollectionMagicMetadata get magicMetadata => _mmd ?? CollectionMagicMetadata.fromEncodedJson(mMdEncodedJson ?? '{}'); @@ -70,21 +68,21 @@ class Collection { } Collection copyWith({ - int id, - User owner, - String encryptedKey, - String keyDecryptionNonce, - String name, - String encryptedName, - String nameDecryptionNonce, - CollectionType type, - CollectionAttributes attributes, - List sharees, - List publicURLs, - int updationTime, - bool isDeleted, - String mMdEncodedJson, - int mMdVersion, + int? id, + User? owner, + String? encryptedKey, + String? keyDecryptionNonce, + String? name, + String? encryptedName, + String? nameDecryptionNonce, + CollectionType? type, + CollectionAttributes? attributes, + List? sharees, + List? publicURLs, + int? updationTime, + bool? isDeleted, + String? mMdEncodedJson, + int? mMdVersion, }) { final Collection result = Collection( id ?? this.id, @@ -117,14 +115,14 @@ class Collection { 'nameDecryptionNonce': nameDecryptionNonce, 'type': typeToString(type), 'attributes': attributes?.toMap(), - 'sharees': sharees?.map((x) => x?.toMap())?.toList(), - 'publicURLs': publicURLs?.map((x) => x?.toMap())?.toList(), + 'sharees': sharees?.map((x) => x?.toMap()).toList(), + 'publicURLs': publicURLs?.map((x) => x?.toMap()).toList(), 'updationTime': updationTime, 'isDeleted': isDeleted, }; } - factory Collection.fromMap(Map map) { + factory Collection.fromMap(Map? map) { if (map == null) { throw Exception('Argument is null'); } @@ -162,9 +160,9 @@ enum CollectionType { } class CollectionAttributes { - final String encryptedPath; - final String pathDecryptionNonce; - final int version; + final String? encryptedPath; + final String? pathDecryptionNonce; + final int? version; CollectionAttributes({ this.encryptedPath, @@ -184,7 +182,7 @@ class CollectionAttributes { return map; } - factory CollectionAttributes.fromMap(Map map) { + factory CollectionAttributes.fromMap(Map? map) { if (map == null) { throw Exception('Argument is null'); } @@ -198,13 +196,13 @@ class CollectionAttributes { } class User { - int id; + int? id; String email; - String name; + String? name; User({ this.id, - this.email, + required this.email, this.name, }); @@ -216,7 +214,7 @@ class User { }; } - factory User.fromMap(Map map) { + factory User.fromMap(Map? map) { if (map == null) { throw Exception('Argument is null'); } @@ -237,15 +235,15 @@ class PublicURL { String url; int deviceLimit; int validTill; - bool enableDownload = true; - bool passwordEnabled = false; + bool enableDownload; + bool passwordEnabled; PublicURL({ - this.url, - this.deviceLimit, - this.validTill, - this.enableDownload, - this.passwordEnabled, + required this.url, + required this.deviceLimit, + required this.validTill, + this.enableDownload = true, + this.passwordEnabled = false, }); Map toMap() { @@ -258,7 +256,7 @@ class PublicURL { }; } - factory PublicURL.fromMap(Map map) { + factory PublicURL.fromMap(Map? map) { if (map == null) { throw Exception('Argument is null'); }