#flutter
Вопрос:
Код отлично работал с версией flutter 2.2.1, но когда я обновил его, он не работает. Я получаю следующую ошибку:
Error: The argument type 'Object' can't be assigned to the parameter type 'R'.
- 'Object' is from 'dart:core'.
return ResponseFormat<R>(Status.SUCCESS, '', tList ?? R);
Я реализовал следующее:
Future<ResponseFormat<R>> doApiGetCall<T extends ResponseUni, R>(
T obj, String url) async {
final http.Client client = http.Client();
try {
final http.Response response = await client.get(Uri.parse('$url'),);
final ResponseApi psApiResponse = ResponseApi(response);
if (psApiResponse.isSuccessful()) {
final dynamic hashMap = json.decode(response.body);
if (!(hashMap is Map)) {
final List<T>? tList = <T>[];
hashMap.forEach((dynamic data) {
tList?.add(obj.fromMap(data as dynamic));
});
return ResponseFormat<R>(Status.SUCCESS, '', tList ?? R); //// I am getting error here
} else {
return ResponseFormat<R>(Status.SUCCESS, '', obj.fromMap(hashMap));
}
} else {
return ResponseFormat<R>(
Status.ERROR, psApiResponse.errorMessage,null);
}
} finally {
client.close();
}
}
Класс responseformat
class ResponseFormat<T>
{
ResponseFormat(this.status, this.message, this.value);
Status? status;
final String? message;
T? value;
}