maybeOf static method

FormState? maybeOf(
  1. BuildContext context

Returns the FormState of the closest Form widget which encloses the given context, or null if none is found.

Typical usage is as follows:

FormState? form = Form.maybeOf(context);

Calling this method will create a dependency on the closest Form in the context, if there is one.

See also:

  • Form.of, which is similar to this method, but asserts if no Form ancestor is found.


static FormState? maybeOf(BuildContext context) {
  final _FormScope? scope = context.dependOnInheritedWidgetOfExactType<_FormScope>();
  return scope?._formState;