easy method
Widget
easy(
- NotifierBuilder<
T?> widget, { - Widget onError(
- String? error
- Widget? onLoading,
- Widget? onEmpty,
- void onLoadTap()?,
Implementation
Widget easy(
NotifierBuilder<T?> widget, {
Widget Function(String? error)? onError,
Widget? onLoading,
Widget? onEmpty,
void Function()? onLoadTap,
}) {
return SimpleBuilder(builder: (_) {
if (status.isLoading) {
return onLoading ?? const Center(child: BaseLoadingView());
} else if (status.isError) {
return onError != null
? onError(status.errorMessage)
: Center(
child: BasePlaceholderView(
title: "${status.errorMessage}",
onTap: onLoadTap,
));
} else if (status.isEmpty) {
return onEmpty != null
? onEmpty
: SizedBox.shrink(); // Also can be widget(null); but is risky
}
return widget(state);
});
}