2023-08-07 10:32:24 +08:00
|
|
|
|
import 'dart:convert';
|
2023-07-27 15:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'api.dart';
|
|
|
|
|
|
import 'request_interceptor.dart';
|
|
|
|
|
|
import 'request_interceptor_log.dart';
|
|
|
|
|
|
import 'response_interceptor.dart';
|
|
|
|
|
|
import 'response_interceptor_log.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class BaseProvider extends GetConnect with Api {
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onInit() {
|
|
|
|
|
|
httpClient.baseUrl = baseUrl;
|
|
|
|
|
|
httpClient.addRequestModifier(requestInterceptor);
|
|
|
|
|
|
httpClient.addResponseModifier(responseInterceptor);
|
|
|
|
|
|
httpClient.addRequestModifier(requestLogInterceptor);
|
|
|
|
|
|
httpClient.addResponseModifier(responseLogInterceptor);
|
|
|
|
|
|
httpClient.timeout = 15.seconds;
|
|
|
|
|
|
super.onInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2023-08-07 10:32:24 +08:00
|
|
|
|
Future<Response<T>> post<T>(String? url, body,
|
|
|
|
|
|
{String? contentType,
|
|
|
|
|
|
Map<String, String>? headers,
|
|
|
|
|
|
Map<String, dynamic>? query,
|
|
|
|
|
|
Decoder<T>? decoder,
|
|
|
|
|
|
Progress? uploadProgress}) async {
|
2023-08-02 09:22:39 +08:00
|
|
|
|
// print("post: url:${url} body:${body} contentType:${contentType} headers:${headers} query:${query}");
|
2023-08-07 10:32:24 +08:00
|
|
|
|
|
|
|
|
|
|
print('哈喽请求body体为:${body}');
|
|
|
|
|
|
var res = await super.post(url, body,
|
|
|
|
|
|
contentType: contentType,
|
|
|
|
|
|
headers: headers,
|
|
|
|
|
|
query: query,
|
|
|
|
|
|
decoder: decoder,
|
|
|
|
|
|
uploadProgress: uploadProgress);
|
|
|
|
|
|
if (res.body == null) {
|
|
|
|
|
|
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
2023-07-27 15:29:37 +08:00
|
|
|
|
var rs = {
|
2023-08-02 09:22:39 +08:00
|
|
|
|
"errorMsg": "Network Error!",
|
|
|
|
|
|
"errorCode": -1,
|
2023-07-27 15:29:37 +08:00
|
|
|
|
"data": null,
|
2023-08-02 09:22:39 +08:00
|
|
|
|
"description": "表示成功或是。"
|
2023-07-27 15:29:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
return Response(
|
|
|
|
|
|
request: res.request,
|
|
|
|
|
|
statusCode: -1,
|
|
|
|
|
|
bodyString: res.bodyString,
|
|
|
|
|
|
bodyBytes: res.bodyBytes,
|
|
|
|
|
|
body: rs as T,
|
|
|
|
|
|
statusText: res.statusText,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2023-08-18 18:25:58 +08:00
|
|
|
|
print('得到的数据======>${res.bodyString}');
|
2023-07-27 15:29:37 +08:00
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2023-08-07 10:32:24 +08:00
|
|
|
|
}
|