showButtonMenu method

void showButtonMenu()

Implementation

void showButtonMenu() {
  final PopupMenuThemeData popupMenusTheme = PopupMenuTheme.of(context);
  final RenderBox button = context.findRenderObject()! as RenderBox;
  final RenderBox overlay = Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox;
  _caculateOffsetY();
  Offset _offset = widget.offsetBuilder?.call(_isTop) ?? Offset.zero;
  final RelativeRect position = RelativeRect.fromRect(
    Rect.fromPoints(
      button.localToGlobal(_offset, ancestor: overlay),
      button.localToGlobal(button.size.bottomRight(Offset.zero) + _offset, ancestor: overlay),
    ),
    Offset.zero & overlay.size,
  );
  final List<PopupMenusEntry<T>> items = widget.itemBuilder(context);
  // Only show the menu if there is something to show
  if (items.isNotEmpty) {
    showMenu<T?>(
      context: context,
      elevation: widget.elevation ?? popupMenusTheme.elevation,
      items: items,
      initialValue: widget.initialValue,
      position: position,
      blur: widget.blur,
      shape: widget.shape ?? popupMenusTheme.shape,
      color: widget.color ?? popupMenusTheme.color,
    ).then<void>((T? newValue) {
      if (!mounted) return null;
      if (newValue == null) {
        widget.onCanceled?.call();
        return null;
      }
      widget.onSelected?.call(newValue);
    });
  }
}