FormControl<T> class

A single reactive form control.

A FormControl holds a value of type V, notifies listeners on changes, and provides validation and state management (required, disabled, readonly).

It can be used with simple values or with a TextEditingController for text fields.

Inheritance

Constructors

FormControl({required T initialValue, FormFieldValidator<T>? validator, bool required = false, bool disabled = false, bool readonly = false, bool touched = false, FromRawFunction<T>? fromRaw, ToRawFunction<T>? toRaw})
Creates a FormControl with the provided valueNotifier, validator, and options.

Properties

controller → TextEditingController
no setter
disabled → bool
Whether the control is disabled.
no setter
error → String?
The validation error message, if any.
no setteroverride
fromRaw → FromRawFunction<T>?
final
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
options → FormControlOptions
Options to configure control state (required, disabled, readonly).
final
readonly → bool
Whether the control is readonly.
no setter
required → bool
Whether the control is marked as required.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
toRaw → ToRawFunction<T>?
final
touched → bool
Whether the control has been touched.
no setter
valid → bool
Whether the control's current value is valid.
no setterinherited
validator ↔ FormFieldValidator<T>?
The optional validator function to check the control's value.
getter/setter pair
value → T
Returns the current value of the control.
no setteroverride
valueNotifier → ControlValue<T>
The underlying value notifier holding the current value.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Disposes the ValueNotifier.
override
getRawValue() → Object?
Returns the raw value of the control.
override
markAsTouched({bool notify = true}) → void
markAsUntouched({bool notify = true}) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
refresh() → void
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setDisabled(bool v, {bool notify = true}) → void
Sets whether the control is disabled.
setRawValue(Object? value, {bool notify = true}) → void
Sets the raw value of the control.
override
setReadonly(bool v, {bool notify = true}) → void
Sets whether the control is readonly.
setRequired(bool v, {bool notify = true}) → void
Sets whether the control is marked as required.
setValidator(FormFieldValidator<T>? newValidator, {bool notify = true}) → void
Updates the validator function. @param newValidator The new validator function to set.
setValue(T val, {bool notify = true}) → void
Sets the control value, unless disabled or readonly.
override
toString() → String
A string representation of this object.
inherited

Operators

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