我在抽象类类型 T 上添加了 fromjson 方法,但 dart 显示方法未定义 这是我的代码 我是 dart 和 flutter 的初学者,所以我尝试了 T().fromjson(data) 但不起作用
abstract class JsonConvertable<T> {
T fromJson(Map<String, dynamic> json);
}
class ProductByRemarksController<T extends JsonConvertable<T>>
extends GetxController {
Future<bool> loadProduct(RemarksType remarks) async {
_isloading = true;
update();
try {
final remarksUrl = ApiUrl.productByRemarks(remarks.getName);
final response = await NetworkCaller().getRequiest(url: remarksUrl);
for (final data in response.responseData['data']) {
// this lines show an error
/*
The method 'fromJson' isn't defined for the type 'Type'.
Try correcting the name to the name of an existing method, or defining a method named 'fromJson'.
*/
T product = T.fromJson(data);
}
return true;
} catch (e) {
return false;
}
}
}