readValue<T> method

  1. @protected
T? readValue<T>(
  1. String fieldName, {
  2. T? convertion(
    1. dynamic value
    )?,
  3. T? nullValue,
})

This method is used to read a value from the Map (JSON) data and return it in the defined type.

If it is necessary to carry out a conversion of the read object before it is returned, pass the conversion function in the parameter convertion, with that the function will receive the value informed in the map, and it can be converted as needed.

It is also possible to indicate a default value for cases where the field to be read does not exist in Map or is null.

Use this method within the readValues method that you will override in the inheritance classes to define how the Map will be read for your class.

Implementation

@protected
T? readValue<T>(String fieldName,
    {T? Function(dynamic value)? convertion, T? nullValue}) {
  if (_lastReadedMap[fieldName] != null) {
    return _convertJsonToValue(_lastReadedMap[fieldName], convertion);
  }
  return nullValue;
}