maybeOf method Null safety
- BuildContext context,
- {bool scopeOk = false}
Returns the focusNode of the Focus that most tightly encloses the given BuildContext.
If no Focus node is found before reaching the nearest FocusScope widget, or there is no Focus widget in scope, then this method will return null.
The context
and scopeOk
arguments must not be null.
Calling this function creates a dependency that will rebuild the given context when the focus changes.
See also:
Implementation
static FocusNode? maybeOf(BuildContext context, { bool scopeOk = false }) {
assert(context != null);
assert(scopeOk != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final FocusNode? node = marker?.notifier;
if (node == null) {
return null;
}
if (!scopeOk && node is FocusScopeNode) {
return null;
}
return node;
}