obx method

Widget obx(
  1. NotifierBuilder<T?> widget, {
  2. Widget onError(
    1. String? error
    )?,
  3. Widget? onLoading,
  4. Widget? onEmpty,
})

Implementation

Widget obx(
  NotifierBuilder<T?> widget, {
  Widget Function(String? error)? onError,
  Widget? onLoading,
  Widget? onEmpty,
}) {
  return SimpleBuilder(builder: (_) {
    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 != null
          ? onEmpty
          : SizedBox.shrink(); // Also can be widget(null); but is risky
    }
    return widget(value);
  });
}