initForm method

  1. @mustCallSuper
FutureOr<void> initForm(
  1. BlocxFormEventInit<P> event,
  2. Emitter<BlocxFormState<F, E>> emit
)
inherited

Handles the initial form event.

Stores the optional payload, applies it to formData when present, emits the initial form data to the UI, optionally validates the form, and starts required info fetching when supported.

Implementation

@mustCallSuper
FutureOr<void> initForm(
  BlocxFormEventInit<P> event,
  Emitter<BlocxFormState<F, E>> emit,
) async {
  _payload = event.payload;
  _isUpdate = event.payload != null;

  if (_payload != null) {
    formData = await applyPayloadToFormData(_payload as P);
  }

  emit(BlocxFormStateApplyInitialDataToForm(formData: formData));

  if (validateOnInit) {
    await validateForm(formData, forceFullValidation: true);
  }

  emitState(emit);

  if (isInfoFetcher) {
    add(BlocxFormEventFetchRequiredInfo());
  }
}