fromList method

Record fromList(
  1. List? list, [
  2. Map<String, dynamic>? recordSchemaMap,
  3. Map<String, dynamic>? schemaMap
])

Copies the value of the specified List to this record.

If there is no guarantee that the schema of the List matches the schema of this record, specify the schema map of this record in recordSchemaMap, and the schema map of the entire DataSet in schemaMap if there is a nested Record or RecordList.

Implementation

Record fromList(List<dynamic?>? list,[Map<String,dynamic?>? recordSchemaMap, Map<String,dynamic>? schemaMap]){
  if(list == null || _schema == null){
    return this;
  }
  if(recordSchemaMap == null){
    for(int i = 0; i < min(list.length, _schema!.length); i++){
      FieldSchema field = _schema!.fields[i];
      Object? value = list[i];
      if(field.isView){
        continue;
      }
      if(_dataSet != null && field.schema != null && value != null){
        if(field.isRecord){
          value = _dataSet!.createNestedRecord(field.schema!).fromList(value as List<dynamic?>);
        }else if(field.isRecordList){
          value = _dataSet!.createNestedRecordList(field.schema!).fromList(value as List<dynamic?>);
        }
      }
      setByIndex(i, value);
    }
  }else{
    Map<String,dynamic>? nestedRecordSchemaMap = schemaMap == null ? null : schemaMap["nestedRecord"];
    Map<String,dynamic>? nestedRecordListSchemaMap = schemaMap == null ? null : schemaMap["nestedRecordList"];
    for(int i = 0; i < _schema!.length; i++){
      FieldSchema field = _schema!.fields[i];
      if(field.isView){
        continue;
      }
      Map<String,dynamic>? fieldSchemaMap = recordSchemaMap[field.name];
      if(fieldSchemaMap == null){
        continue;
      }
      Object? value = list[fieldSchemaMap["index"]];
      if(_dataSet != null && field.schema != null && value != null){
        if(field.isRecord){
          value = _dataSet!.createNestedRecord(field.schema!).fromList(
            value as List<dynamic>,
            nestedRecordSchemaMap == null ? null : nestedRecordSchemaMap[fieldSchemaMap["schema"]],
            schemaMap
          );
        }else if(field.isRecordList){
          value = _dataSet!.createNestedRecordList(field.schema!).fromList(
            value as List<dynamic>,
            nestedRecordListSchemaMap == null ? null : nestedRecordListSchemaMap[fieldSchemaMap["schema"]],
            schemaMap
          );
        }
      }
      setByIndex(i, value);
    }
  }
  return this;
}