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