StepperFormState<Success, Failure extends Error>.fromSteps constructor

StepperFormState<Success, Failure extends Error>.fromSteps({
  1. required StepperFormController<dynamic, Error> parent,
  2. required List<StepFormController<dynamic, Error>> steps,
})

Creates a new StepperFormState from a list of individual step controllers.

This factory constructor initializes a StepperFormState with the given parent controller and a list of steps, combining the form fields and statuses from each step into a single state.

The parent controller is assigned to each step, ensuring proper coordination between the step controllers and the parent stepper controller.

Parameters:

Returns: A new instance of StepperFormState with all combined fields, statuses, and an initial step index of 0.

The returned state has:

  • currentStep Set to 0, indicating the starting step of the form.
  • fields Combined form fields from all the steps.
  • status The combined status derived from all the step states.
  • success Set to null initially (to be determined by the form submission).
  • failure Set to null initially (to be determined by the form submission).

Implementation

factory StepperFormState.fromSteps({
  required StepperFormController parent,
  required List<StepFormController> steps,
}) {
  final states = steps.map((item) => item.state).toList();
  for (final step in steps) {
    step.parent = parent;
  }
  final fields = _combineFields(states);
  final status = _deriveCombinedStatus(states);
  return StepperFormState<Success, Failure>(
    currentStep: 0,
    fields: fields,
    status: status,
    success: null,
    failure: null,
  );
}