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) {
final currentStatus = status;
return switch (currentStatus) {
LoadingStatus() =>
onLoading ?? const Center(child: CircularProgressIndicator()),
ErrorStatus() =>
onError != null
? onError(currentStatus.errorMessage)
: Center(
child: Text(
'An error occurred: ${currentStatus.errorMessage}',
),
),
EmptyStatus() => onEmpty ?? const SizedBox.shrink(),
SuccessStatus() => widget(value),
CustomStatus() => onCustom?.call(context) ?? const SizedBox.shrink(),
};
},
);
}