OnFormBuilder constructor
OnFormBuilder({
- Key? key,
- required InjectedForm listenTo,
- required Widget builder(),
- ReactiveModel<
bool?> ? isEnabledRM, - ReactiveModel<
bool?> ? isReadOnlyRM, - WillPopCallback? onWillPop,
Build a form from its child fields
Implementation
OnFormBuilder({
Key? key,
required this.listenTo,
required Widget Function() builder,
this.isEnabledRM,
this.isReadOnlyRM,
//TODO test and document
WillPopCallback? onWillPop,
}) : super(
key: key,
observers: (_) {
return [];
},
dispose: (_, __) {
isEnabledRM?.disposeIfNotUsed();
isReadOnlyRM?.disposeIfNotUsed();
},
shouldRebuild: (old, current) {
return !current.isWaiting;
},
builder: (context, snap, rm) {
final inj = listenTo as InjectedFormImp;
final child = OnReactive(() {
final cached = InjectedFormImp._currentInitializedForm;
InjectedFormImp._currentInitializedForm = inj
.._isEnabled = isEnabledRM?.state ?? inj._isEnabled
.._isReadOnly = isReadOnlyRM?.state ?? inj._isReadOnly;
return Stack(
children: [
builder(),
Builder(
builder: (_) {
InjectedFormImp._currentInitializedForm = cached;
// inj
// .._isEnabled = null
// .._isReadOnly = null;
return const SizedBox(height: 0, width: 0);
},
),
],
);
});
if (onWillPop != null) {
return WillPopScope(child: child, onWillPop: onWillPop);
}
return child;
},
);