• Greg Spencer's avatar
    Add key event handlers that happen before or after the focus traversal (#136280) · 7e1d366a
    Greg Spencer authored
    ## Description
    
    This adds a mechanism for listening to key events before or after focus traversal occurs.
    
    It adds four methods to the public `FocusManager` API:
    
    - `addEarlyKeyEventHandler` - Adds a handler that can handle events before they are given to the focus tree for handling.
    - `removeEarlyKeyEventHandler` - Removes an early event handler.
    - `addLateKeyEventHandler` - Adds a handler that can handle events if they have not been handled by anything in the focus tree.
    - `removeLateKeyEventHandler` - Removes a late event handler.
    
    This allows an app to get notified for a key anywhere, and prevent the focus tree from seeing that event if it handles it.
    
    For the menu system, this allows it to eat an escape key press and close all the open menus.
    
    ## Related Issues
     - https://github.com/flutter/flutter/issues/135334
    
    ## Tests
     - Added tests for new functionality.
    7e1d366a
focus_manager_test.dart 89.1 KB