45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
|
|
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
|
|
Future<Response<T>> post<T>(String? url, body, {String? contentType, Map<String, String>? headers, Map<String, dynamic>? query, Decoder<T>? decoder, Progress? uploadProgress}) async {
|
|
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);
|
|
var rs = {
|
|
"msg": "Network Error!",
|
|
"msgCode": -1,
|
|
"data": null,
|
|
"code": 200
|
|
};
|
|
return Response(
|
|
request: res.request,
|
|
statusCode: -1,
|
|
bodyString: res.bodyString,
|
|
bodyBytes: res.bodyBytes,
|
|
body: rs as T,
|
|
statusText: res.statusText,
|
|
);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
} |