FormControl<T> constructor
- T? value,
- bool nonNullable = true,
- List<
Validator> validators = const [], - List<
AsyncValidator> asyncValidators = const [], - @Deprecated("Use [Validators.debounced] to specify a debounce time for individual asynchronous validators.") int asyncValidatorsDebounceTime = 250,
- bool touched = false,
- bool disabled = false,
Creates a new FormControl instance.
The control can optionally be initialized with a value.
The nonNullable argument is used to determine the state of the control
when the reset method is called without a value. If nonNullable is
true (the default), the reset method will reset the control to the
initial value provided in the constructor. If nonNullable is false,
the reset method will reset the control to null unless a value is
provided.
The control can optionally have validators that validates
the control each time the value changes.
The control can optionally have asyncValidators that validates
asynchronously the control each time the value changes. Asynchronous
validation executes after the synchronous validation, and is performed
only if the synchronous validation is successful. This check allows
forms to avoid potentially expensive async validation processes
(such as an HTTP request) if the more basic validation methods have
already found invalid input.
You can set touched as true to force the validation messages
to show up at the very first time the widget that is bound to this
control builds in the UI.
If disabled is true then the control is disabled by default.
Example:
final priceControl = FormControl<double>(defaultValue: 0.0);
Implementation
FormControl({
T? value,
bool nonNullable = true,
super.validators,
super.asyncValidators,
@Deprecated(
"Use [Validators.debounced] to specify a debounce time for individual asynchronous validators.",
)
/// **DEPRECATED**: Use [Validators.debounced] to specify a debounce time for
/// individual asynchronous validators. This property will be removed in a
/// future major version.
super.asyncValidatorsDebounceTime,
super.touched,
super.disabled,
}) : _defaultValue = nonNullable ? value : null {
if (value != null) {
this.value = value;
} else {
updateValueAndValidity();
}
}