openPopupMenu method

Future<void> openPopupMenu()

Only has effect when popup is fully closed.

Implementation

Future<void> openPopupMenu() async {
  if (popupState == PopupMenuState.CLOSED) {
    final childRect = _getChildRect();
    if (childRect == null) return;

    popupState = PopupMenuState.OPENING;

    final openMenuCompleter = Completer<void>();
    _entry = OverlayEntry(builder: (context) {
      return Stack(
        children: [
          Positioned.fill(
            child: GestureDetector(
              onTap: closePopupMenu,
            ),
          ),
          CustomSingleChildLayout(
            delegate: PopupMenuRouteLayout(
              buttonRect: childRect,
              overlayRect: _getOverlayRect(context),
              calculatePopupPosition: widget.calculatePopupPosition,
            ),
            child: AnimatedPopupMenu(
              key: _menuKey,
              backgroundBuilder: widget.backgroundBuilder,
              onFullyOpened: () {
                openMenuCompleter.complete();
              },
              child: ConstrainedBox(
                constraints: const BoxConstraints(
                  minWidth: _kMenuMinWidth,
                  maxWidth: _kMenuMaxWidth,
                ),
                child: SingleChildScrollView(
                  child: IntrinsicWidth(
                    stepWidth: _kMenuWidthStep,
                    child: _buildPopupBody(),
                  ),
                ),
              ),
            ),
          ),
        ],
      );
    });

    final overlay = Overlay.of(context)!;
    overlay.insert(_entry!);

    await openMenuCompleter.future;
    popupState = PopupMenuState.OPENED;
  }
}