Commit 44a1d5de authored by xuxiaohuis's avatar xuxiaohuis
Browse files

add sendRequest loading

No related merge requests found
Showing with 20 additions and 2 deletions
+20 -2
......@@ -52,17 +52,23 @@ abstract class BaseController<M> extends SuperController{
VoidCallback? failCallback,
}) {
if (bindViewState && showLoadingDialog) {
if (bindViewState) {
LogD("showLoadingDialog");
viewState.value = ViewStateLoading();
}
if (showLoadingDialog) {
Get.showLoading();
}
sendRequestBlock.then((result) {
if (result.isSuccess()) {
bool isEmpty = (judgeEmptyCallback != null)
? judgeEmptyCallback(result)
: result.isEmpty();
if (showLoadingDialog) {
Get.hideLoading();
}
if (!isEmpty || (emptyAsSuccess && isEmpty)) {
if (bindViewState) {
viewState.value = ViewStateSuccess(result.data);
......@@ -74,6 +80,10 @@ abstract class BaseController<M> extends SuperController{
if (bindViewState) {
viewState.value = ViewStateEmpty();
}
if (showLoadingDialog) {
Get.hideLoading();
showToast("${result.msg}(${result.code})");
}
if (emptyCallback != null) {
emptyCallback();
}
......@@ -82,6 +92,10 @@ abstract class BaseController<M> extends SuperController{
if (bindViewState) {
viewState.value = ViewStateFail(result.code, result.msg);
}
if (showLoadingDialog) {
Get.hideLoading();
showToast("${result.msg}(${result.code})");
}
if (failCallback != null) {
failCallback();
}
......@@ -92,6 +106,10 @@ abstract class BaseController<M> extends SuperController{
viewState.value =
ViewStateError(requestException.code, requestException.message);
}
if (showLoadingDialog) {
Get.hideLoading();
showToast("${requestException.message}(${requestException.code})");
}
if (failCallback != null) {
failCallback();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment