writeValue method
void
writeValue(})
This method is used to save the values in a Map (JSON)
, this will be
used when the class is being exported to a JSON
,
To do this, you must enter the fieldName
parameter with the name of the
Map key, and in the value
parameter the value that will be recorded
in Map.
If it is necessary to convert the exported value to another format, inform
the convertion
parameter the conversion method, this method will receive
the current value of the property, and may return the value as needed.
It will also be possible to indicate whether null values should be ignored
using the ignoreNull
parameter.
Use this method inside the writeValues method that you will override to
define how the output JSON
will be formed.
Implementation
@protected
void writeValue(String fieldName, dynamic value,
{bool? ignoreNull,
bool? exportIfChanged,
dynamic Function(dynamic value)? convertion}) {
ignoreNull ??= _ignoreNulls;
if (ignoreNull && value == null) {
return;
}
if (value is List && convertion != null) {
value = value.map((item) => convertion(item)).toList();
} else {
value = (convertion != null ? convertion(value) : value);
}
exportIfChanged ??= _exportOnlyChanged;
if (exportIfChanged && _originalMap[fieldName] == value) {
return;
}
_lastWritedMap[fieldName] = _convertValueToJson(value);
}