app-starlock/star_lock/lib/network/api_provider_base.dart
Daisy 819b04e697 1,新增电子钥匙重置接口
2,新增电子钥匙详情-操作记录接口
3,新增公用组件边线button
4,完善发送钥匙部分逻辑
2023-08-17 18:54:19 +08:00

60 lines
1.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:convert';
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 {
// print("post: url:${url} body:${body} contentType:${contentType} headers:${headers} query:${query}");
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);
var rs = {
"errorMsg": "Network Error!",
"errorCode": -1,
"data": null,
"description": "表示成功或是。"
};
return Response(
request: res.request,
statusCode: -1,
bodyString: res.bodyString,
bodyBytes: res.bodyBytes,
body: rs as T,
statusText: res.statusText,
);
}
print('得到的数据======>$res');
return res;
}
}