readList<T> method

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

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;

}