render method

Widget render(
  1. BuildContext context, {
  2. WidgetOrLoaderBuilder<X>? builder,
  3. WidgetDataBuilder<X>? successFn,
  4. WidgetErrorBuilder errorFn = kErrorHandler,
  5. bool isSliver = false,
  6. SimpleWidgetBuilder loadingFn = kLoader,
  7. bool allowNull = false,
  8. bool? crossFade = true,
})

Implementation

Widget render(
  BuildContext context, {
  WidgetOrLoaderBuilder<X>? builder,
  WidgetDataBuilder<X>? successFn,
  WidgetErrorBuilder errorFn = kErrorHandler,
  bool isSliver = false,
  SimpleWidgetBuilder loadingFn = kLoader,
  bool allowNull = false,
  bool? crossFade = true,
}) {
  assert(successFn != null || builder != null,
      "Must have either builder or successFn");

  if (isSliver == true) {
    final _oldLoad = loadingFn;
    loadingFn = () => SliverToBoxAdapter(child: (_oldLoad()));

    final _oldErr = errorFn;
    errorFn = (context, err, stack) =>
        SliverToBoxAdapter(child: _oldErr(context, err, stack));
  }

  Widget widget;
  if (hasError) {
    widget = errorFn(context, this.error!, null);
  } else if (hasData || allowNull == true) {
    widget = successFn != null ? successFn(data!) : builder!(data, loadingFn);
  } else {
    widget = builder != null ? builder(null, loadingFn) : loadingFn();
  }
  return (crossFade != true || isSliver == true)
      ? widget
      : AnimatedSwitcher(
          duration: const Duration(milliseconds: 300), child: widget);
}