FormGroup constructor Null safety

  1. Map<String, AbstractControl> controls,
  2. {List<ValidatorFunction> validators = const [],
  3. List<AsyncValidatorFunction> asyncValidators = const [],
  4. int asyncValidatorsDebounceTime = 250,
  5. bool disabled = false}

Creates a new FormGroup instance.

When instantiating a FormGroup, pass in a Map of child controls as the first argument.

The key for each child registers the name for the control.


final form = FromGroup({
  'name': FormControl(defaultValue: 'John Doe'),
  'email': FormControl(),

The group can optionally have validators that validates the group each time the value changes.

The group can optionally have asyncValidators that validates asynchronously the group 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.

If disabled is true then all children controls of the groups are disabled by default.

See also AbstractControl.validators


  Map<String, AbstractControl<dynamic>> controls, {
  List<ValidatorFunction> validators = const [],
  List<AsyncValidatorFunction> asyncValidators = const [],
  int asyncValidatorsDebounceTime = 250,
  bool disabled = false,
}) : super(
        validators: validators,
        asyncValidators: asyncValidators,
        asyncValidatorsDebounceTime: asyncValidatorsDebounceTime,
        disabled: disabled,
      ) {

  if (disabled) {
    markAsDisabled(emitEvent: false);