of static method
- BuildContext context
Returns the AutofillGroupState of the closest AutofillGroup widget which encloses the given context.
If no instance is found, this method will assert in debug mode and throw an exception in release mode.
Calling this method will create a dependency on the closest
AutofillGroup in the context
.
An AutofillGroupState can be used to register an AutofillClient when it enters this AutofillGroup (for example, when an EditableText is mounted or reparented onto the AutofillGroup's subtree), and unregister an AutofillClient when it exits (for example, when an EditableText gets unmounted or reparented out of the AutofillGroup's subtree).
The AutofillGroupState class also provides an AutofillGroupState.attach method that can be called by TextInputClients that support autofill, instead of TextInput.attach, to create a TextInputConnection to interact with the platform's text input system.
See also:
- AutofillGroup.maybeOf, which is similar to this method, but returns null if an AutofillGroup cannot be found.
- EditableTextState, where this method is used to retrieve the closest AutofillGroupState.
Implementation
static AutofillGroupState of(BuildContext context) {
final AutofillGroupState? groupState = maybeOf(context);
assert(() {
if (groupState == null) {
throw FlutterError(
'AutofillGroup.of() was called with a context that does not contain an '
'AutofillGroup widget.\n'
'No AutofillGroup widget ancestor could be found starting from the '
'context that was passed to AutofillGroup.of(). This can happen '
'because you are using a widget that looks for an AutofillGroup '
'ancestor, but no such ancestor exists.\n'
'The context used was:\n'
' $context',
);
}
return true;
}());
return groupState!;
}