of static method

_AppFormState of(
  1. BuildContext context
)
override

Returns the FormState of the closest Form widget which encloses the given context.

Typical usage is as follows:

FormState form = Form.of(context);
form.save();

If no Form ancestor is found, this will assert in debug mode, and throw an exception in release mode.

Calling this method will create a dependency on the closest Form in the context.

See also:

  • Form.maybeOf, which is similar to this method, but returns null if no Form ancestor is found.

Implementation

static _AppFormState of(BuildContext context) {
  final state = context.findAncestorStateOfType<_AppFormState>();
  assert(state != null, 'No AppFormState found in context');

  return state!;
}