set method

void set(
  1. String? fieldName,
  2. Object? value, {
  3. int? field_table_id,
  4. Type? targetType,
})

Implementation

void set(String? fieldName, Object? value,
    {int? field_table_id, Type? targetType}) {
  if (fieldName == null) throw ArgumentError("fieldName must not be null");
  int? tid = field_table_id ?? table_id;
  if (tid == null) throw ArgumentError("There must be a table_id.");
  if (targetType == int) {
    // Values which are supposed to be ints but are empty strings should be null
    if (value.runtimeType == String) {
      String v = value as String;
      if (v.length == 0) value = null;
    }
  }
  FieldStruct fs = FieldStruct(tid, fieldName, value);
  int index = _fieldStructList.length;
  String uniqueKey = DataTools.convertUniqueKey(tid, fieldName);
  if (_fieldDataMap.containsKey(uniqueKey)) {
    _fieldStructList[_fieldDataMap[uniqueKey]!] = fs;
  } else {
    _fieldStructList.add(fs);
    _fieldDataMap[uniqueKey] = index;
  }
}