request<T> method
void
request<T>({})
同步回调的网络请求
Implementation
void request<T>(
{required Future<BaseResp<T>> future,
bool isNeedLoading = true,
bool isLoadingCancelable = false,
String? loadingTxt,
bool isShowErrorToast = false,
bool isShowErrorDetailToast = false,
OnSuccess<T>? onSuccess,
OnFailed? onFailed}) {
// 根据需要展示loading弹框
if (isNeedLoading) {
showLoading(loadingTxt: loadingTxt, cancelable: isLoadingCancelable);
}
future.then(
(resp) => {
_checkSuccessFailed(resp, (T? data) {
// 接口请求成功
if (!isFinishing()) {
if (isNeedLoading) {
dismissLoading();
}
if (onSuccess != null) {
onSuccess(data);
}
}
}, (e) {
// 接口请求失败
if (!isFinishing()) {
if (isNeedLoading) {
dismissLoading();
}
if (isShowErrorDetailToast == true) {
showToast(e.detailMessage);
} else if (isShowErrorToast == true) {
showToast(e.message);
}
_onFailed(onFailed, e);
}
})
}, onError: (e) {
_onFailed(onFailed, CstException.buildException(e));
}).catchError((e) {
return e;
});
}