render method
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,
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);
}