baseRefreshBuilderState method

Widget baseRefreshBuilderState(
  1. Widget widget(
    1. T? state,
    2. BuildContext context,
    3. ScrollPhysics physics
    ), {
  2. ScrollController? scrollController,
  3. bool validNullable = true,
  4. bool? shimmer,
  5. Color? baseColor,
  6. Color? highlightColor,
  7. BaseHeader? header,
  8. BaseFooter? footer,
  9. Widget onPlaceholderWidget()?,
  10. Widget? placeholderEmptyWidget,
  11. String? placeholderEmptyTitle,
  12. String? placeholderEmptyMessage,
  13. TextStyle? placeholderEmptyTitleStyle(
    1. TextStyle
    )?,
  14. TextStyle? placeholderEmptyMessageStyle(
    1. TextStyle
    )?,
  15. bool firstRefresh = false,
  16. VoidCallback? onRefresh,
  17. VoidCallback? onLoading,
  18. void onReloadTap()?,
})

Implementation

Widget baseRefreshBuilderState(
  Widget Function(T? state, BuildContext context, ScrollPhysics physics)
      widget, {
  ScrollController? scrollController,
  bool validNullable = true,
  bool? shimmer,
  Color? baseColor,
  Color? highlightColor,
  BaseHeader? header,
  BaseFooter? footer,
  Widget Function()? onPlaceholderWidget,
  Widget? placeholderEmptyWidget,
  String? placeholderEmptyTitle,
  String? placeholderEmptyMessage,
  TextStyle? Function(TextStyle)? placeholderEmptyTitleStyle,
  TextStyle? Function(TextStyle)? placeholderEmptyMessageStyle,
  bool firstRefresh = false,
  VoidCallback? onRefresh,
  VoidCallback? onLoading,
  void Function()? onReloadTap,
}) {
  _placeholderEmptyTitle = placeholderEmptyTitle;
  return SimpleBuilder(builder: (_) {
    return BaseRefresh.builder(
      controller: refreshController,
      scrollController: scrollController,
      header: header,
      footer: footer,
      onRefresh: implementationOnRefresh && !status.isLoading
          ? (onRefresh ?? () async => onRequestPage(kFirstPage))
          : null,
      onLoad: implementationOnLoad && state != null && !status.isLoading
          ? (onLoading ?? () async => onRequestPage(page + 1))
          : null,
      childBuilder: (context, physics) {
        Widget? emptyWidget() {
          if (status.isLoading && shimmer == true) {
            return BaseShimmer(
              visible: true,
              child: widget(state, context, physics),
              baseColor: baseColor,
              highlightColor: highlightColor,
            );
          }

          final titleStyle = Get.isDarkMode
              ? setDarkPlaceholderTitleTextStyle
              : setLightPlaceholderTitleTextStyle;
          final messageStyle = Get.isDarkMode
              ? setDarkPlaceholderMessageTextStyle
              : setLightPlaceholderMessageTextStyle;
          return onPlaceholderWidget != null
              ? onPlaceholderWidget()
              : BasePlaceholderView(
                  title: getPlaceholderTitle(placeholderEmptyTitle),
                  message: getPlaceholderMessage(placeholderEmptyMessage),
                  titleStyle: placeholderEmptyTitleStyle?.call(titleStyle),
                  messageStyle:
                      placeholderEmptyMessageStyle?.call(messageStyle),
                  // 指定当前页面的占位图路径(网络默认placeholder_remote错误除外, 默认placeholder_empty)
                  image: placeholderEmptyWidget,
                  onTap: onReloadTap ??
                      () {
                        change(state, status: RxStatus.loading());
                        onRequestPage(page);
                      },
                );
        }

        return (state == null && !status.isSuccess ||
                (validNullable && state.isEmptyOrNull))
            ? emptyWidget() ?? SizedBox()
            : widget(state, context, physics);
      },
    );
  });
}