OnBuilder<T>.orElse constructor
OnBuilder<T>.orElse ({
- Key? key,
- IObservable<
T> ? listenTo, - List<
IObservable> ? listenToMany, - Widget onIdle()?,
- Widget onWaiting()?,
- Widget onError(
- dynamic error,
- void refreshError()
- Widget onData(
- T data
- required Widget orElse(
- T data
- SideEffects<
T> ? sideEffects, - ShouldRebuild? shouldRebuild,
- Object? watch()?,
- String? debugPrintWhenRebuild,
Explicitly listenTo one or more injected state and reinvoke its onBuilder callback each time an injected state emits a notification.
For each OnBuilder widget flavor there is method like equivalent:
//Widget-like
OnBuilder(
listenTo: counter,
builder: () => Text('${counter.state}'),
),
//Method-like
counter.rebuild(
() => Text('{counter.state}'),
),
//
//Widget-like
OnBuilder.data(
listenTo: counter,
builder: (data) => Text('$data')),
),
//Method-like
counter.rebuild.onData(
(data) => Text(data),
),
//Widget-like
OnBuilder.all(
listenTo: counter,
onIdle: () => Text('onIdle'),
onWaiting: () => Text('onWaiting'),
onError: (err, errorRefresh) => Text('onError'),
onData: (data) => Text('$data'),
)
//Method-like
counter.rebuild.onAll(
onIdle: () => Text('onIdle'),
onWaiting: () => Text('onWaiting'),
onError: (err, errorRefresh) => Text('onError'),
onData: (data) => Text('$data'),
),
//
//Widget-like
OnBuilder.orElse(
listenTo: counter,
onWaiting: () => Text('onWaiting'),
orElse: (_) => Text('{counter.state}'),
),
//Method-like
counter.rebuild.onOrElse(
onWaiting: () => Text('onWaiting'),
orElse: (_) => Text('{counter.state}'),
),
Implementation
OnBuilder.orElse({
Key? key,
IObservable<T>? listenTo,
List<IObservable>? listenToMany,
Widget Function()? onIdle,
Widget Function()? onWaiting,
Widget Function(dynamic error, void Function() refreshError)? onError,
Widget Function(T data)? onData,
required Widget Function(T data) orElse,
SideEffects<T>? sideEffects,
ShouldRebuild? shouldRebuild,
Object? Function()? watch,
String? debugPrintWhenRebuild,
}) : assert(listenTo != null || listenToMany != null),
super(
key: key,
observers: (_) => listenTo != null
? [listenTo as ReactiveModelImp]
: listenToMany!.cast<ReactiveModelImp>(),
builder: (_, snap, ___) {
return snap.onOrElse<Widget>(
onIdle: onIdle,
onWaiting: onWaiting,
onError: onError,
onData: onData != null ? (_) => onData(_) : null,
orElse: (_) => orElse(_),
);
},
sideEffects: sideEffects,
shouldRebuild: shouldRebuild,
);