obx method

Widget obx(
  1. NotifierBuilder<NsgBaseControllerData?> widget, {
  2. Widget onError(
    1. String? error
    )?,
  3. Widget? onLoading,
  4. Widget? onEmpty,
  5. bool needProgressBar = true,
})

Implementation

Widget obx(
  NotifierBuilder<NsgBaseControllerData?> widget, {
  Widget Function(String? error)? onError,
  Widget? onLoading,
  Widget? onEmpty,
  bool needProgressBar = true,
}) {
  return Observer(
    builder: (_) {
      if (status.isLoading) {
        if (onLoading != null || needProgressBar) {
          return onLoading ?? getDefaultProgressIndicator();
        } else {
          return widget(NsgBaseController.emptyData);
        }
      } 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();
      }
      return widget(value);
    },
  );
}