OnFormBuilder constructor

OnFormBuilder({
  1. Key? key,
  2. required InjectedForm listenTo,
  3. required Widget builder(),
  4. ReactiveModel<bool?>? isEnabledRM,
  5. ReactiveModel<bool?>? isReadOnlyRM,
  6. 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;
        },
      );