readList<T> method
This method is used to read a list of values from a Map (JSON)
and
return it in the list of 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
List<T?>? readList<T>(String fieldName,
{T? Function(dynamic value)? convertion, List<T?>? nullValue}) {
if (_lastReadedMap[fieldName] != null) {
return (_lastReadedMap[fieldName] as List)
.map<T?>((value) => _convertJsonToValue(value, convertion))
.toList();
}
return nullValue;
}