fromList method
Read DataSet from the Map which has Record and RecordList expressed in List format.
List format records and record lists are vulnerable to field increases and decreases when interacting with others. Instead, the output size can be minimized.
For example
{
"User":{
"header":{
"":["hoge",20,false]
},
"recordList":{
"career":[
["career1","from":"2020/01/01","2020/01/30",["detail1","detail2"]],
["career2","from":"2020/02/01","2020/04/30",["detail1","detail2"]]
]
}
}
}
Implementation
DataSet fromList(Map<String,dynamic>? map,{bool isListHeader:true, bool isListRecordList:true}){
if(map == null){
return this;
}
MapEntry dsEntry = map.entries.first;
if(name == null){
name = dsEntry.key;
}
Map<String,dynamic?> dsMap = dsEntry.value;
Map<String,dynamic?>? schemaMap = dsMap["schema"];
Map<String?,dynamic?>? headerSchemata = schemaMap == null ? null : schemaMap["header"];
Map<String?,dynamic?>? headers = dsMap["header"];
if(headers != null){
headers.forEach(
(name, value){
Record? header = _headers[name?.length == 0 ? null : name];
if(header != null){
if(isListHeader){
Map<String,dynamic>? headerSchema = headerSchemata == null ? null : headerSchemata[name?.length == 0 ? null : name];
header.fromList(value, headerSchema, schemaMap);
}else{
header.fromMap(value);
}
}
}
);
}
Map<String?,dynamic?>? recordListSchemata = schemaMap == null ? null : schemaMap["recordList"];
Map<String?,dynamic?>? recordLists = dsMap["recordList"];
if(recordLists != null){
recordLists.forEach(
(name, value){
RecordList? list = _recordLists[name?.length == 0 ? null : name];
if(list != null){
if(isListRecordList){
Map<String,dynamic?>? recordListSchema = recordListSchemata == null ? null : recordListSchemata[name?.length == 0 ? null : name];
list.fromList(value, recordListSchema, schemaMap);
}else{
list.fromMap(value);
}
}
}
);
}
return this;
}