dismiss static method

Future<void> dismiss({
  1. bool animate = true,
})

Dismiss the currently active bubble.

If animate is true (default) the closing animation will be played. If animate is false the bubble is removed immediately (useful for testing or when you need an immediate dismissal).

Implementation

static Future<void> dismiss({bool animate = true}) async {
  // Cancel any pending dismiss animation timer
  _dismissAnimationTimer?.cancel();
  _dismissAnimationTimer = null;

  if (animate) {
    // trigger the 'dismiss' animation
    BubbleLabel._animationController.state = false;

    // Use a Completer to allow awaiting the timer completion
    final completer = Completer<void>();

    _dismissAnimationTimer = Timer(0.3.sec, () {
      _dismissAnimationTimer = null;
      _activeAnchorKey = null; // Clear anchor key
      _bubbleLabelOverlayRenderBoxController.state =
          null; // Clear overlay reference
      _removeOverlayEntries();
      BubbleLabel.controller.refresh();
      completer.complete();
    });

    return completer.future;
  } else {
    // no animation -> remove immediately
    _activeAnchorKey = null; // Clear anchor key
    _bubbleLabelOverlayRenderBoxController.state =
        null; // Clear overlay reference
    _removeOverlayEntries();
    BubbleLabel._animationController.state = null;
    BubbleLabel.controller.refresh();
  }
}