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 = createDependency
? context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>()
: context.getInheritedWidgetOfExactType<_FocusInheritedScope>();
return switch (scope?.notifier) {
null => null,
FocusScopeNode() when !scopeOk => null,
final FocusNode node => node,
};
}