PrismFormController class

Headless form state manager.

Holds values, validation errors, and touched fields for a form; drives submission lifecycle via the sealed PrismFormStatus. Usable inside PrismForm (widget-managed) or standalone for custom UIs.

final controller = PrismFormController();

// From any listener (e.g. ValueListenableBuilder):
controller.setValue('email', 'a@b.co');
controller.setTouched('email');

if (await controller.submit(
  (values) => api.register(values),
)) {
  // success
}
Inheritance

Constructors

PrismFormController({Map<String, Object?> initialValues = const {}})
Creates a controller with optional initialValues.

Properties

errors → Map<String, String>
Current validation errors (unmodifiable view).
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
status → PrismFormStatus
Current submission lifecycle.
no setter
submitAttempted → bool
Whether the user has attempted a submit (error display gate).
no setter
touched → Set<String>
Fields the user has interacted with.
no setter
values → Map<String, Object?>
Current field values (unmodifiable view).
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
errorOf(String name) → String?
The current error message for name, if any.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
registerValidator(String name, PrismValidator validator) → void
Registers the validator for name. Called by field widgets.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
reset() → void
Clears values, errors, touched state, and returns to pristine.
setTouched(String name) → void
Marks name as touched (typically on focus/blur) and validates it.
setValue(String name, Object? value) → void
Sets value for name, marks the form as edited, and revalidates the field once the user has touched it or attempted a submit.
showError(String name) → bool
Whether an error should currently be displayed for name.
submit(Future<void> onSubmit(Map<String, Object?> values)) → Future<bool>
Validates and, when clean, runs onSubmit with the current values.
toString() → String
A string representation of this object.
inherited
unregisterValidator(String name) → void
Removes the validator for name (field unmounted).
validate() → bool
Validates every registered field. Returns true when all pass.

Operators

operator ==(Object other) → bool
The equality operator.
inherited