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,
})
inherited

底层建立下拉刷新

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(ObjectUtil.isNotEmpty(widgetList)) {
    if(isBusy || isError){
      widgetList = [
        SliverToBoxAdapter(
          child: Container(),
        )
      ];
    }
  }else if(ObjectUtil.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(ObjectUtil.isNotEmpty(widgetList)){
    useSliverWidget = true;
  }else{
    useSliverWidget = false;
  }


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

  return SizeCacheWidget(
    child: child,
  );
}