control method

  1. @override
AbstractControl control(
  1. String name
)
override

Retrieves a child control given the control's name or path.

The argument name is a dot-delimited string that define the path to the control.

Throws FormControlNotFoundException if no control founded with the specified name/path.

Example:

final form = FormGroup({
  'total': FormControl<int>(value: 20),
  'person': FormGroup({
    'name': FormControl<String>(value: 'John'),
  }),
});

Retrieves a control

form.control('total');

Retrieves a nested control

form.control('person.name');

Implementation

@override
AbstractControl<dynamic> control(String name) {
  final namePath = name.split(_controlNameDelimiter);
  if (namePath.length > 1) {
    final control = findControlInCollection(namePath);
    if (control != null) {
      return control;
    }
  } else if (contains(name)) {
    return _controls[name]!;
  }

  throw FormControlNotFoundException(controlName: name);
}