openPopup method

Future<void> openPopup()

Implementation

Future<void> openPopup() {
  final NavigatorState navigator = Navigator.of(context);
  final RenderBox itemBox = context.findRenderObject()! as RenderBox;
  final Offset target = itemBox.localToGlobal(
    itemBox.size.center(Offset.zero),
    ancestor: navigator.context.findRenderObject(),
  );
  final Rect itemRect = target & itemBox.size;
  assert(_dropdownRoute == null, 'You can NOT open it twice');
  _dropdownRoute = PopUpRoute<T>(
    width: widget.contentWidth,
    target: target,
    below: widget.below!,
    contentHeight: widget.contentHeight,
    content: widget.content(context),
    buttonRect: itemRect,
    elevation: 4,
    capturedThemes:
        InheritedTheme.capture(from: context, to: navigator.context),
    transitionAnimationDuration: Duration(milliseconds: 500),
    verticalOffset: widget.verticalOffset,
    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
  );

  return navigator.push(_dropdownRoute!).then((T? newValue) {
    removePopUpRoute();
    if (!mounted || newValue == null) return;
  });
}