OnBuilder<T> constructor
OnBuilder<T> ({
- Key? key,
- IObservable<
T> ? listenTo, - List<
IObservable> ? listenToMany, - required Widget builder(),
- 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({
Key? key,
IObservable<T>? listenTo,
List<IObservable>? listenToMany,
required Widget Function() builder,
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: (_, __, ___) => builder(),
sideEffects: sideEffects,
shouldRebuild: shouldRebuild,
);