FormControl<T> constructor

FormControl<T>({
  1. T? value,
  2. List<ValidatorFunction> validators = const [],
  3. List<AsyncValidatorFunction> asyncValidators = const [],
  4. int asyncValidatorsDebounceTime = 250,
  5. bool touched = false,
  6. bool disabled = false,
})

Creates a new FormControl instance.

The control can optionally be initialized with a value.

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 an asyncValidatorsDebounceTime in millisecond to set a delay time before trigger async validators. This is useful for minimizing request to a server. The default value is 250 milliseconds.

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,
  List<ValidatorFunction> validators = const [],
  List<AsyncValidatorFunction> asyncValidators = const [],
  int asyncValidatorsDebounceTime = 250,
  bool touched = false,
  bool disabled = false,
}) : super(
        validators: validators,
        asyncValidators: asyncValidators,
        asyncValidatorsDebounceTime: asyncValidatorsDebounceTime,
        disabled: disabled,
        touched: touched,
      ) {
  if (value != null) {
    this.value = value;
  } else {
    updateValueAndValidity();
  }
}