|
|
|
|
@ -15,14 +15,11 @@ abstract class ApiClient {
|
|
|
|
|
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
|
|
|
|
|
Future<http.Response> postJsonForResponse<T>(String url, T jsonObject,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
Future<http.Response> postJsonForResponse<T>(String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
|
|
|
|
|
Future<U> getJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
Future<U> getJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
|
|
|
|
|
Future<http.Response> getJsonForResponse<T>(String url,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
Future<http.Response> getJsonForResponse<T>(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ApiClientImp implements ApiClient {
|
|
|
|
|
@ -38,9 +35,11 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
headers0.addAll(headers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response =
|
|
|
|
|
await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers0, retryTimes: retryTimes);
|
|
|
|
|
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: headers0, retryTimes: retryTimes);
|
|
|
|
|
try {
|
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
|
log("responseBody:${response.body}");
|
|
|
|
|
}
|
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
|
log("statusCode:${response.statusCode}");
|
|
|
|
|
}
|
|
|
|
|
@ -54,8 +53,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<http.Response> postJsonForResponse<T>(String url, T jsonObject,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
Future<http.Response> postJsonForResponse<T>(String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
String? requestBody;
|
|
|
|
|
if (jsonObject != null) {
|
|
|
|
|
requestBody = jsonEncode(jsonObject);
|
|
|
|
|
@ -102,7 +100,6 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
loggerService.logInfo(jsonDecode(requestBody).toString());
|
|
|
|
|
loggerService.logInfo("------Response------");
|
|
|
|
|
loggerService.logInfo(jsonDecode(response.body).toString());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 500) {
|
|
|
|
|
@ -158,8 +155,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<http.Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) =>
|
|
|
|
|
_withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
|
|
|
|
|
Future<http.Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<U> getJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url,
|
|
|
|
|
@ -179,8 +175,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<http.Response> getJsonForResponse<T>(String url,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
Future<http.Response> getJsonForResponse<T>(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
if (headers == null) {
|
|
|
|
|
headers = {'Content-Type': 'application/json'};
|
|
|
|
|
} else {
|
|
|
|
|
@ -191,8 +186,7 @@ class ApiClientImp implements ApiClient {
|
|
|
|
|
|
|
|
|
|
bool isFirstCall = true;
|
|
|
|
|
|
|
|
|
|
Future<http.Response> _getForResponse(String url,
|
|
|
|
|
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
Future<http.Response> _getForResponse(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
|
|
|
|
|
try {
|
|
|
|
|
var headers0 = <String, String>{};
|
|
|
|
|
if (token != null) {
|
|
|
|
|
|