buildBaseViewStateEasyRefresh method

Widget buildBaseViewStateEasyRefresh(
  1. {ScrollController scrollController,
  2. Widget busyWidget,
  3. Widget footWidget,
  4. ViewStateWidgetBuilder emptyWidgetBuilder,
  5. ViewStateWidgetBuilder errorWidgetBuilder,
  6. bool showErrorWidget = true,
  7. bool showEmptyWidget = true,
  8. bool showBusyWidget = true,
  9. Function onLoad,
  10. Function onRefresh,
  11. List<Widget> widgetList,
  12. Widget widget}
)

底层建立下拉刷新

Implementation

Widget buildBaseViewStateEasyRefresh({
  ScrollController scrollController,
  Widget busyWidget,
  Widget footWidget,
  ViewStateWidgetBuilder emptyWidgetBuilder,
  ViewStateWidgetBuilder errorWidgetBuilder,
  bool showErrorWidget = true,
  bool showEmptyWidget = true,
  bool showBusyWidget = true,
  Function onLoad,
  Function onRefresh,
  List<Widget> widgetList,
  Widget widget,
}){


  if(isNotEmpty(widgetList)) {
    if(isBusy || isError){
      widgetList = [
        SliverToBoxAdapter(
          child: Container(),
        )
      ];
    }
  }else if(isNotEmpty(widget)){
    if(isBusy || isError){
      widget = Container();
    }
  }


  Widget emptyErrorWidget = buildRefreshNoDataWidget(
      viewState: this,
      busyWidget: busyWidget,
      emptyWidgetBuilder: emptyWidgetBuilder,
      errorWidgetBuilder: errorWidgetBuilder,
      showErrorWidget: showErrorWidget,
      showEmptyWidget: showEmptyWidget,
      showBusyWidget: showBusyWidget
  );


  bool useSliverWidget;

  if(isNotEmpty(widgetList)){
    useSliverWidget = true;
  }else{
    useSliverWidget = false;
  }



  return useSliverWidget? EasyRefresh.custom(
    slivers: widgetList,
    scrollController: scrollController,
    enableControlFinishRefresh: true,
    enableControlFinishLoad: true,
    taskIndependence: true,
    controller: refreshController,
    emptyWidget: emptyErrorWidget,
    onLoad: isBusy? null : isEmpty(onLoad)? null :  () async{
      onLoad.call();
    },
    onRefresh: isBusy? null : () async{
      onRefresh.call();
    },
  ) : EasyRefresh(
    enableControlFinishLoad: true,
    enableControlFinishRefresh: true,
    scrollController: scrollController,
    emptyWidget: emptyErrorWidget,
    taskIndependence: true,
    child: widget,
    controller: refreshController,
    onRefresh: isBusy? null : () async{
      onRefresh.call();
    },
    onLoad: isBusy? null : isEmpty(onLoad)? null :  () async{
      onLoad.call();
    },
  );
}