maybeOf static method
- BuildContext context, {
- bool scopeOk = false,
- bool createDependency = true,
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.
If createDependency
is true (which is the default), calling this
function creates a dependency that will rebuild the given context when the
focus node gains or loses focus.
See also:
Implementation
static FocusNode? maybeOf(BuildContext context, { bool scopeOk = false, bool createDependency = true }) {
final _FocusInheritedScope? scope;
if (createDependency) {
scope = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
} else {
scope = context.getInheritedWidgetOfExactType<_FocusInheritedScope>();
}
final FocusNode? node = scope?.notifier;
if (node == null) {
return null;
}
if (!scopeOk && node is FocusScopeNode) {
return null;
}
return node;
}