Fix FocusManager constructor (#75894)
The FocusManager constructor was registering global event handlers on the shared RawKeyboard instance and the global pointer router. This posed a few problems: (1) there was no way to unregister these handlers, and (2) instantiating a second FocusManager would overwrite the existing focus manager's RawKeyboard handler. This was manifesting in unexpected ways, such as the fact that constructing a second BuildOwner (for a parallel tree, for instance) was obliterating the event handler for the main BuildOwner's focus manager, thus messing with focus. This change separates those global event registrations into a dedicated method, registerGlobalHandlers(), and overrides dispose() to properly unregister those handlers.
This commit is contained in:
@@ -897,7 +897,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
FlutterError.demangleStackTrace = _oldStackTraceDemangler;
|
||||
_pendingExceptionDetails = null;
|
||||
_parentZone = null;
|
||||
buildOwner!.focusManager = FocusManager();
|
||||
buildOwner!.focusManager.dispose();
|
||||
buildOwner!.focusManager = FocusManager()..registerGlobalHandlers();
|
||||
// Disabling the warning because @visibleForTesting doesn't take the testing
|
||||
// framework itself into account, but we don't want it visible outside of
|
||||
// tests.
|
||||
|
||||
Reference in New Issue
Block a user