requestHttp function
Future<void>
requestHttp(
- RequestType type,
- Http dio,
- String url, {
- Map<
String, dynamic> ? p, - bool isShowDialog = false,
- bool dialogAllClear = false,
- bool isShowError = true,
- bool isShowHint = true,
- bool disposeJson = false,
- bool? isFromData,
- Function? notLogin,
- required RequestSucceed succeed,
- RequestFailure? failure,
Implementation
Future<void> requestHttp(
RequestType type,
Http dio,
String url, {
Map<String, dynamic>? p,
bool isShowDialog = false,
bool dialogAllClear = false,
bool isShowError = true,
bool isShowHint = true,
bool disposeJson = false,
bool? isFromData,
Function? notLogin,
required RequestSucceed succeed,
RequestFailure? failure,
}) async {
Response response;
dio.options.extra.update(keyShowDialog, (item) => isShowDialog,
ifAbsent: () => isShowDialog);
dio.options.extra.update(keyDialogAllClear, (item) => dialogAllClear,
ifAbsent: () => dialogAllClear);
dio.options.extra
.update(keyShowError, (item) => isShowError, ifAbsent: () => isShowError);
dio.options.extra
.update(keyShowHint, (item) => isShowHint, ifAbsent: () => isShowHint);
dio.options.extra.update(keyDisposeJson, (item) => disposeJson,
ifAbsent: () => disposeJson);
try {
switch (type) {
case RequestType.Get:
response = await dio.get(url, queryParameters: p);
break;
case RequestType.Post:
var data = isFromData ?? postDataIsFromData
? (p != null ? FormData.fromMap(p) : null)
: p;
response = await dio.post(url, data: data);
break;
}
succeed(response);
} on DioError catch (e) {
// LogUtil.printLog("UnAuthorizedException");
if (e.error is UnAuthorizedException) {
if (notLogin != null) notLogin();
} else {
LogUtil.printLog("error");
if (failure != null) failure(e);
}
}
}