baseRefreshState method

Widget baseRefreshState(
  1. NotifierBuilder<T?> widget, {
  2. ScrollController? scrollController,
  3. bool validNullable = true,
  4. bool? shimmer,
  5. Color? baseColor,
  6. Color? highlightColor,
  7. Widget onPlaceholderWidget()?,
  8. String? placeholderEmptyImagePath,
  9. String? placeholderEmptyTitle,
  10. String? placeholderEmptyMessage,
  11. bool firstRefresh = false,
  12. VoidCallback? onRefresh,
  13. VoidCallback? onLoading,
  14. void onReloadTap()?,
})

Implementation

Widget baseRefreshState(
  NotifierBuilder<T?> widget, {
  ScrollController? scrollController,
  bool validNullable = true,
  bool? shimmer,
  Color? baseColor,
  Color? highlightColor,
  Widget Function()? onPlaceholderWidget,
  String? placeholderEmptyImagePath,
  String? placeholderEmptyTitle,
  String? placeholderEmptyMessage,
  bool firstRefresh = false,
  VoidCallback? onRefresh,
  VoidCallback? onLoading,
  void Function()? onReloadTap,
}) {
  _placeholderEmptyTitle = placeholderEmptyTitle;
  return SimpleBuilder(builder: (_) {
    Widget? emptyWidget() {
      if (status.isLoading && shimmer == true) {
        return BaseShimmer(
          visible: true,
          child: widget(state),
          baseColor: baseColor,
          highlightColor: highlightColor,
        );
      }
      return onPlaceholderWidget != null
          ? onPlaceholderWidget()
          : BasePlaceholderView(
              title: getPlaceholderTitle(placeholderEmptyTitle),
              message: getPlaceholderMessage(placeholderEmptyMessage),
              // 指定当前页面的占位图路径(网络默认placeholder_remote错误除外, 默认placeholder_empty)
              image: placeholderEmptyImagePath,
              onTap: onReloadTap ??
                  () {
                    change(state, status: RxStatus.loading());
                    onRequestPage(page);
                  },
            );
    }

    return BaseRefresh(
      controller: refreshController,
      scrollController: scrollController,
      emptyWidget:
          (validNullable && state.isEmptyOrNull) ? emptyWidget() : null,
      firstRefresh: firstRefresh,
      onRefresh: implementationOnRefresh && !status.isLoading
          ? (onRefresh ?? () async => onRequestPage(kFirstPage))
          : null,
      onLoading: implementationOnLoad && state != null && !status.isLoading
          ? (onLoading ?? () async => onRequestPage(page + 1))
          : null,
      child: (state == null && !status.isSuccess ||
              (validNullable && state.isEmptyOrNull))
          ? emptyWidget() ?? SizedBox()
          : widget(state),
    );
  });
}