app-starlock/star_lock/lib/network/api_provider_base.dart
Daisy b98307f300 1,完成清空操作记录接口调试
2,完成创建锁分组接口及逻辑处理
3,完成锁分组列表接口调试
2023-08-28 17:35:30 +08:00

84 lines
2.5 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 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../tools/toast.dart';
import 'package:get/get.dart';
import '../appRouters.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('得到的数据======>bodyString:${res.bodyString} body:${res.body} bodyBytes:${res.bodyBytes} status:${res.status} statusText:${res.statusText} statusCode:${res.statusCode}');
getDataResult(res.body);
return res;
}
getDataResult(T){
switch(T["errorCode"]){
case 403:
Get.offNamedUntil(Routers.starLockLoginPage, (route) => false);
break;
case 500:
Toast.show(msg: "服务器错误");
break;
case 421:
case 422:
case 430:
Toast.show(msg: T["errorMsg"]);
break;
case 425:
Toast.show(msg: "用户不存在");
break;
case 10001:
Toast.show(msg: "数据不存在");
break;
}
}
}