obx method
Widget
obx(
- NotifierBuilder<
T> widget, { - Widget onError(
- String? error
- Widget? onLoading,
- Widget? onEmpty,
- WidgetBuilder? onCustom,
Implementation
Widget obx(
NotifierBuilder<T> widget, {
Widget Function(String? error)? onError,
Widget? onLoading,
Widget? onEmpty,
WidgetBuilder? onCustom,
}) {
return Observer(builder: (context) {
if (status.isLoading) {
return onLoading ?? const Center(child: CircularProgressIndicator());
} else if (status.isError) {
return onError != null
? onError(status.errorMessage)
: Center(child: Text('A error occurred: ${status.errorMessage}'));
} else if (status.isEmpty) {
return onEmpty ??
const SizedBox.shrink(); // Also can be widget(null); but is risky
} else if (status.isSuccess) {
return widget(value);
} else if (status.isCustom) {
return onCustom?.call(context) ??
const SizedBox.shrink(); // Also can be widget(null); but is risky
}
return widget(value);
});
}