buildViewStateWidget function

Widget buildViewStateWidget(
  1. BaseViewState viewState,
  2. Function idleWidget,
  3. {ViewStateWidgetBuilder emptyWidgetBuilder,
  4. Widget busyWidget,
  5. ViewStateWidgetBuilder errorWidgetBuilder,
  6. Widget errorDataWidget,
  7. bool showErrorWidget = true,
  8. bool showEmptyWidget = true,
  9. bool showBusyWidget = true}
)

Implementation

Widget buildViewStateWidget(BaseViewState viewState, Function idleWidget, {ViewStateWidgetBuilder emptyWidgetBuilder, Widget busyWidget, ViewStateWidgetBuilder errorWidgetBuilder, Widget errorDataWidget, bool showErrorWidget = true, bool showEmptyWidget = true, bool showBusyWidget = true}){
  if(viewState.isIdle){
    return idleWidget();
  }else if(viewState.isError && viewState.httpError?.httpErrorType == HttpErrorType.EmptyDataError){
    if (showEmptyWidget) {
      if(emptyWidgetBuilder != null){
        return emptyWidgetBuilder.call(viewState);
      }else{
        return emptyWidget.call(viewState);
      }
    } else{
      return idleWidget();
    }
  }else if(viewState.isError){
    if (showErrorWidget) {
      if(errorDataWidget != null){
        return errorWidgetBuilder.call(viewState);
      }else {
        return errorWidget.call(viewState);
      }
    } else{
      return idleWidget();
    }
  }else if (viewState.isBusy) {
    if (showBusyWidget) {
      return busyWidget??pageLoading;
    }else{
      return idleWidget();
    }
  } else{
    return Container();
  }
}