mobx method
Widget
mobx(
- NotifierBuilder<
T?> widget, { - Widget? onError(
- MError? error
- Widget? onLoading,
- Widget? onEmpty,
- WidgetBuilder? onCustom,
Implementation
Widget mobx(
NotifierBuilder<T?> widget, {
Widget? Function(MError? error)? onError,
Widget? onLoading,
Widget? onEmpty,
WidgetBuilder? onCustom,
}) {
return SimpleBuilder(builder: (_) {
if (status.isLoading) {
return onLoading ?? const Center(child: CircularProgressIndicator());
} else if (status.isError) {
return onError != null
? onError(status.error) ?? const SizedBox.shrink()
: Center(
child:
Text('${LocaleKeys.state_error_tips}: ${status.errorMsg}'));
} 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(_) ??
const SizedBox.shrink(); // Also can be widget(null); but is risky
}
return widget(value);
});
}