I am trying to create an abstract data model where i pass data and type a and then is return list, but when i can't call T.fromJson()
method, note that passes type has method fromJson()
class DataList<T> {
final bool success;
dynamic data;
InfosResponse({
this.success,
List<dynamic> data,
}) {
castDataToList(data);
}
factory DataList.fromJson(Map<String, dynamic> json) {
return DataList(
success: json['success'],
data: json['data'],
);
}
void castDataToList(jsonData) {
this.data = List<T>.from(jsonData.map((x) => T.fromJson(x)));
}
}