Browse Source

turn factories into static methods so it is allowed to return null

ashilkn 2 years ago
parent
commit
c05cfb9578

+ 6 - 12
lib/models/billing_plan.dart

@@ -16,10 +16,8 @@ class BillingPlans {
     };
     };
   }
   }
 
 
-  factory BillingPlans.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return BillingPlans(
     return BillingPlans(
       plans: List<BillingPlan>.from(
       plans: List<BillingPlan>.from(
@@ -51,10 +49,8 @@ class FreePlan {
     };
     };
   }
   }
 
 
-  factory FreePlan.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return FreePlan(
     return FreePlan(
       storage: map['storage'],
       storage: map['storage'],
@@ -95,10 +91,8 @@ class BillingPlan {
     };
     };
   }
   }
 
 
-  factory BillingPlan.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return BillingPlan(
     return BillingPlan(
       id: map['id'],
       id: map['id'],

+ 8 - 16
lib/models/collection.dart

@@ -122,10 +122,8 @@ class Collection {
     };
     };
   }
   }
 
 
-  factory Collection.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
     final sharees = (map['sharees'] == null || map['sharees'].length == 0)
     final sharees = (map['sharees'] == null || map['sharees'].length == 0)
         ? <User>[]
         ? <User>[]
         : List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
         : List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
@@ -182,10 +180,8 @@ class CollectionAttributes {
     return map;
     return map;
   }
   }
 
 
-  factory CollectionAttributes.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return CollectionAttributes(
     return CollectionAttributes(
       encryptedPath: map['encryptedPath'],
       encryptedPath: map['encryptedPath'],
@@ -214,10 +210,8 @@ class User {
     };
     };
   }
   }
 
 
-  factory User.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return User(
     return User(
       id: map['id'],
       id: map['id'],
@@ -256,10 +250,8 @@ class PublicURL {
     };
     };
   }
   }
 
 
-  factory PublicURL.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return PublicURL(
     return PublicURL(
       url: map['url'],
       url: map['url'],

+ 2 - 4
lib/models/collection_file_item.dart

@@ -31,10 +31,8 @@ class CollectionFileItem {
     };
     };
   }
   }
 
 
-  factory CollectionFileItem.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
 
 
     return CollectionFileItem(
     return CollectionFileItem(
       map['id'],
       map['id'],

+ 6 - 12
lib/models/magic_metadata.dart

@@ -21,10 +21,8 @@ class MagicMetadata {
 
 
   factory MagicMetadata.fromJson(dynamic json) => MagicMetadata.fromMap(json);
   factory MagicMetadata.fromJson(dynamic json) => MagicMetadata.fromMap(json);
 
 
-  factory MagicMetadata.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
     return MagicMetadata(
     return MagicMetadata(
       visibility: map[magicKeyVisibility] ?? visibilityVisible,
       visibility: map[magicKeyVisibility] ?? visibilityVisible,
     );
     );
@@ -43,10 +41,8 @@ class PubMagicMetadata {
   factory PubMagicMetadata.fromJson(dynamic json) =>
   factory PubMagicMetadata.fromJson(dynamic json) =>
       PubMagicMetadata.fromMap(json);
       PubMagicMetadata.fromMap(json);
 
 
-  factory PubMagicMetadata.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
     return PubMagicMetadata(
     return PubMagicMetadata(
       editedTime: map[pubMagicKeyEditedTime],
       editedTime: map[pubMagicKeyEditedTime],
       editedName: map[pubMagicKeyEditedName],
       editedName: map[pubMagicKeyEditedName],
@@ -68,10 +64,8 @@ class CollectionMagicMetadata {
   factory CollectionMagicMetadata.fromJson(dynamic json) =>
   factory CollectionMagicMetadata.fromJson(dynamic json) =>
       CollectionMagicMetadata.fromMap(json);
       CollectionMagicMetadata.fromMap(json);
 
 
-  factory CollectionMagicMetadata.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception('Argument is null');
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
     return CollectionMagicMetadata(
     return CollectionMagicMetadata(
       visibility: map[magicKeyVisibility] ?? visibilityVisible,
       visibility: map[magicKeyVisibility] ?? visibilityVisible,
     );
     );

+ 2 - 4
lib/models/subscription.dart

@@ -32,10 +32,8 @@ class Subscription {
     return 'year' == period;
     return 'year' == period;
   }
   }
 
 
-  factory Subscription.fromMap(Map<String, dynamic>? map) {
-    if (map == null) {
-      throw Exception("Argument is null");
-    }
+  static fromMap(Map<String, dynamic>? map) {
+    if (map == null) return null;
     return Subscription(
     return Subscription(
       productID: map['productID'],
       productID: map['productID'],
       storage: map['storage'],
       storage: map['storage'],