FocusManager constructor

FocusManager()

Creates an object that manages the focus tree.

This constructor is rarely called directly. To access the FocusManager, consider using the FocusManager.instance accessor instead (which gets it from the WidgetsBinding singleton).

This newly constructed focus manager does not have the necessary event handlers registered to allow it to manage focus. To register those event handlers, callers must call registerGlobalHandlers. See the documentation in that method for caveats to watch out for.

Implementation

FocusManager() {
  if (kFlutterMemoryAllocationsEnabled) {
    ChangeNotifier.maybeDispatchObjectCreation(this);
  }
  if (kIsWeb || defaultTargetPlatform != TargetPlatform.android) {
    // It appears that some Android keyboard implementations can cause
    // app lifecycle state changes: adding this listener would cause the
    // text field to unfocus as the user is trying to type.
    //
    // Until this is resolved, we won't be adding the listener to Android apps.
    // https://github.com/flutter/flutter/pull/142930#issuecomment-1981750069
    _appLifecycleListener = _AppLifecycleListener(_appLifecycleChange);
    WidgetsBinding.instance.addObserver(_appLifecycleListener!);
  }
  rootScope._manager = this;
}