setByName method

void setByName(
  1. String name,
  2. Object? value
)

Set the value of the specified field name.

It throw exceptions in the following cases.

  • If you specify a field name that is not defined.
  • If you specify a field that is a view.
  • If input conversion is not possible.

Implementation

void setByName(String name, Object? value){
  FieldSchema? fs = _schema?.fieldMap[name];
  if(fs == null){
    throw Exception("The specified field does not exist. name=$name, schema=$_schema");
  }
  if(fs.isView){
    throw Exception("The specified field is view. name=$name, schema=$_schema");
  }
  if(value != null){
    if(!fs.instanceof(value)){
      value = fs.parseValue(_dataSet, this, value);
      if(!fs.instanceof(value)){
        throw Exception("The type doesn't match. name=$name, type=${value.runtimeType}, schema=$_schema");
      }
    }
  }
  _values![name] = value;
  if(_validated.containsKey(name))_validated[name] = null;
}