listFromJson<T> static method
Implementation
static List<T>? listFromJson<T>(Map<String, dynamic> json, String attribute,
T Function(Map<String, dynamic>) callback) {
try {
List<T>? list = <T>[];
if (json[attribute] != null &&
json[attribute] is List &&
json[attribute].length > 0) {
json[attribute].forEach((v) {
if (v is Map<String, dynamic>) {
list?.add(callback(v));
}
});
} else {
list = null;
}
return list;
} catch (e) {
throw Exception('Error while parsing $attribute[$e]');
}
}