app-starlock/star_lock/lib/network/api_provider_base.dart
Daisy fb25ad51f5 1,新增国家及区号选择列表
2,密码/卡/指纹/遥控详情新增去设置其他选项的入口
3,新增找回密码接口调试及逻辑处理
2023-08-07 10:32:24 +08:00

59 lines
1.7 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,
);
}
return res;
}
}