@@ -90,39 +90,41 @@ class ModelEntity {
9090 ModelEntity .fromMap (Map <String , dynamic > data,
9191 {ModelInfo ? model, bool check = true })
9292 : _model = model,
93- id = IdUid .fromString (data['id' ] as String ? ),
94- lastPropertyId = IdUid .fromString (data['lastPropertyId' ] as String ? ),
95- uidRequest = data['uidRequest' ] as bool ? ?? false ,
93+ id = IdUid .fromString (data[ModelEntityKey .id] as String ? ),
94+ lastPropertyId =
95+ IdUid .fromString (data[ModelEntityKey .lastPropertyId] as String ? ),
96+ uidRequest = data[ModelEntityKey .uidRequest] as bool ? ?? false ,
9697 _properties = [],
9798 _relations = [],
9899 _backlinks = [] {
99- name = data[' name' ] as String ? ;
100- externalName = data[' externalName' ] as String ? ;
101- flags = data[' flags' ] as int ? ?? 0 ;
100+ name = data[ModelEntityKey . name] as String ? ;
101+ externalName = data[ModelEntityKey . externalName] as String ? ;
102+ flags = data[ModelEntityKey . flags] as int ? ?? 0 ;
102103
103- final properties = data[' properties' ] as List ;
104+ final properties = data[ModelEntityKey . properties] as List ;
104105 for (final p in properties) {
105106 _properties.add (ModelProperty .fromMap (p as Map <String , dynamic >, this ));
106107 }
107108
108- final relations = data[' relations' ] as List ? ;
109+ final relations = data[ModelEntityKey . relations] as List ? ;
109110 if (relations != null ) {
110111 for (final p in relations) {
111112 _relations.add (ModelRelation .fromMap (p as Map <String , dynamic >));
112113 }
113114 }
114115
115- final backlinks = data[' backlinks' ] as List ? ;
116+ final backlinks = data[ModelEntityKey . backlinks] as List ? ;
116117 if (backlinks != null ) {
117118 for (final p in backlinks) {
118119 _backlinks.add (ModelBacklink .fromMap (p as Map <String , dynamic >));
119120 }
120121 }
121122
122- if (data['constructorParams' ] != null ) {
123- constructorParams = (data['constructorParams' ] as List <dynamic >)
124- .map ((dynamic e) => e as String )
125- .toList (growable: false );
123+ if (data[ModelEntityKey .constructorParams] != null ) {
124+ constructorParams =
125+ (data[ModelEntityKey .constructorParams] as List <dynamic >)
126+ .map ((dynamic e) => e as String )
127+ .toList (growable: false );
126128 }
127129
128130 if (check) validate ();
@@ -183,19 +185,19 @@ class ModelEntity {
183185 /// JSON.
184186 Map <String , dynamic > toMap ({bool forModelJson = false }) {
185187 final ret = < String , dynamic > {};
186- ret['id' ] = id.toString ();
187- ret[' lastPropertyId' ] = lastPropertyId.toString ();
188- ret[' name' ] = name;
189- if (externalName != null ) ret[' externalName' ] = externalName;
190- if (flags != 0 ) ret[' flags' ] = flags;
191- ret[' properties' ] =
188+ ret[ModelEntityKey .id ] = id.toString ();
189+ ret[ModelEntityKey . lastPropertyId] = lastPropertyId.toString ();
190+ ret[ModelEntityKey . name] = name;
191+ if (externalName != null ) ret[ModelEntityKey . externalName] = externalName;
192+ if (flags != 0 ) ret[ModelEntityKey . flags] = flags;
193+ ret[ModelEntityKey . properties] =
192194 properties.map ((p) => p.toMap (forModelJson: forModelJson)).toList ();
193- ret[' relations' ] =
195+ ret[ModelEntityKey . relations] =
194196 relations.map ((r) => r.toMap (forModelJson: forModelJson)).toList ();
195197 if (! forModelJson) {
196- ret[' backlinks' ] = backlinks.map ((r) => r.toMap ()).toList ();
197- ret[' constructorParams' ] = constructorParams;
198- ret[' uidRequest' ] = uidRequest;
198+ ret[ModelEntityKey . backlinks] = backlinks.map ((r) => r.toMap ()).toList ();
199+ ret[ModelEntityKey . constructorParams] = constructorParams;
200+ ret[ModelEntityKey . uidRequest] = uidRequest;
199201 }
200202 return ret;
201203 }
@@ -316,3 +318,17 @@ class ModelEntity {
316318 return result;
317319 }
318320}
321+
322+ /// Map keys for properties of this entity.
323+ class ModelEntityKey {
324+ static const String id = 'id' ;
325+ static const String lastPropertyId = 'lastPropertyId' ;
326+ static const String name = 'name' ;
327+ static const String externalName = 'externalName' ;
328+ static const String flags = 'flags' ;
329+ static const String properties = 'properties' ;
330+ static const String relations = 'relations' ;
331+ static const String backlinks = 'backlinks' ;
332+ static const String constructorParams = 'constructorParams' ;
333+ static const String uidRequest = 'uidRequest' ;
334+ }
0 commit comments