StepperFormState<Success, Failure extends Error>.fromSteps constructor
StepperFormState<Success, Failure extends Error>.fromSteps ({
- required StepperFormController<
dynamic, Error> parent, - required List<
StepFormController< steps,dynamic, Error> >
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:
parent: The StepperFormController that manages the entire multi-step form process.steps: A list of StepFormController instances representing the individual steps in the form.
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
nullinitially (to be determined by the form submission). - failure Set to
nullinitially (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,
);
}