onAnimationStatusChanged property

ValueChanged<AnimationStatus>? onAnimationStatusChanged
final

An optional callback that is invoked when the AnimationStatus of the menu changes during open and close animations.

If animated is false, this callback will only be invoked with AnimationStatus.completed when the menu is opened, and AnimationStatus.dismissed when the menu is closed.

This callback provides a way to determine when the menu is opening or closing. This is necessary because the MenuController.isOpen property remains true throughout the opening, opened, and closing phases, and therefore cannot be used on its own to determine the current animation direction.

This example shows how to use the onAnimationStatusChanged callback to create a MenuAnchor that will toggle between opening and closing.
link
MenuAnchor(
  animated: true,
  onAnimationStatusChanged: (AnimationStatus status) {
    // Typically, animationStatus would be stored in a State object.
    animationStatus = status;
  },
  menuChildren: <Widget>[MenuItemButton(onPressed: () {}, child: const Text('Menu Item'))],
  builder: (BuildContext context, MenuController controller, Widget? child) {
    return IconButton(
      onPressed: () {
        if (animationStatus.isForwardOrCompleted) {
          controller.close();
        } else {
          controller.open();
        }
      },
      icon: const Icon(Icons.more_vert),
    );
  },
);

Defaults to null.

Implementation

final ValueChanged<AnimationStatus>? onAnimationStatusChanged;