onCloseRequested property
Called when a request is made to close the menu.
This callback can be used to add a delay or a closing animation before the menu is hidden.
This callback is triggered every time MenuController.close is called while this menu is open.
This callback is also triggered when a sibling RawMenuAnchor is opened while this menu is open. In this case, the callback can be used to add a delay or a closing animation while the sibling menu opens. When implementing this behavior, consider disabling interactions so that the closing menu does not interfere with the opening sibling menu. Also consider disabling semantics, focus, and hit testing for the closing menu for the duration of the closing animation.
Pending timers or animations started in a previous call to onCloseRequested should be canceled when this callback is triggered to prevent them from closing the menu at an unintended time.
If the menu is not closed, this callback will also be called when the root menu anchor is scrolled and when the screen is resized.
After a close request is intercepted and closing behaviors have completed,
the hideOverlay callback should be called. This callback sets
MenuController.isOpen to false and hides the menu overlay widget. If the
RawMenuAnchor is used in a themed menu that plays a closing animation,
hideOverlay should be called after the closing animation has ended,
since the animation plays on the overlay itself. This means that
MenuController.isOpen will stay true while closing animations are
running.
Calling hideOverlay after disposal is a no-op, meaning it will not
trigger onClose or hide the menu overlay.
Typically, onCloseRequested consists of the following steps:
- Optionally start the closing animation and wait for it to complete.
- Call
hideOverlay(whose call chain eventually invokes onClose).
Throughout the closing sequence, menus should typically not be focusable or interactive.
Defaults to a callback that immediately hides the menu.
Implementation
final RawMenuAnchorCloseRequestedCallback onCloseRequested;