Browse Source

prefer factories that do not return null

ashilkn 2 years ago
parent
commit
6201b77809
1 changed files with 12 additions and 4 deletions
  1. 12 4
      lib/models/collection.dart

+ 12 - 4
lib/models/collection.dart

@@ -125,7 +125,9 @@ class Collection {
   }
 
   factory Collection.fromMap(Map<String, dynamic> map) {
-    if (map == null) return null;
+    if (map == null) {
+      throw Exception('Argument is null');
+    }
     final sharees = (map['sharees'] == null || map['sharees'].length == 0)
         ? <User>[]
         : List<User>.from(map['sharees'].map((x) => User.fromMap(x)));
@@ -183,7 +185,9 @@ class CollectionAttributes {
   }
 
   factory CollectionAttributes.fromMap(Map<String, dynamic> map) {
-    if (map == null) return null;
+    if (map == null) {
+      throw Exception('Argument is null');
+    }
 
     return CollectionAttributes(
       encryptedPath: map['encryptedPath'],
@@ -213,7 +217,9 @@ class User {
   }
 
   factory User.fromMap(Map<String, dynamic> map) {
-    if (map == null) return null;
+    if (map == null) {
+      throw Exception('Argument is null');
+    }
 
     return User(
       id: map['id'],
@@ -253,7 +259,9 @@ class PublicURL {
   }
 
   factory PublicURL.fromMap(Map<String, dynamic> map) {
-    if (map == null) return null;
+    if (map == null) {
+      throw Exception('Argument is null');
+    }
 
     return PublicURL(
       url: map['url'],