Repository: flutter/flutter
File: packages/flutter/lib/src/widgets/raw_menu_anchor.dart (Dart)

Code before:
  }

  @override
  void handleCloseRequest() {
    // Changes in MediaQuery.sizeOf(context) cause RawMenuAnchor to close during
    // didChangeDependencies. When this happens, calling setState during the
    // closing sequence (handleCloseRequest -> onCloseRequested -> hideOverlay)
    // will throw an error, since we'd be scheduling a build during a build. We
    // avoid this by checking if we're in a build, and if so, we schedule the
    // close for the next frame.
    if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) {
      widget.onCloseRequested(close);
    } else {
      SchedulerBinding.instance.addPostFrameCallback((_) {
        if (mounted) {
          widget.onCloseRequested(close);
        }
      }, debugLabel: 'RawMenuAnchor.handleCloseRequest');
    }
  }

  Widget _buildOverlay(BuildContext context, OverlayChildLayoutInfo layoutInfo) {
    final Matrix4 transform = layoutInfo.childPaintTransform;
    final Size anchorSize = layoutInfo.childSize;

    // Transform the anchor rectangle corners using the full transform matrix
    final Offset topLeft = MatrixUtils.transformPoint(transform, Offset.zero);
    final Offset bottomRight = MatrixUtils.transformPoint(
      transform,
      anchorSize.bottomRight(Offset.zero),
    );

    final RawMenuOverlayInfo info = RawMenuOverlayInfo(
      anchorRect: Rect.fromPoints(topLeft, bottomRight),
      overlaySize: layoutInfo.overlaySize,
      position: _menuPosition,
      tapRegionGroupId: root.menuController,
    );

    return widget.overlayBuilder(context, info);
  }

  @override
  Widget buildAnchor(BuildContext context) {
    final Widget child = Shortcuts(
      includeSemantics: false,
      shortcuts: _kMenuTraversalShortcuts,
      child: TapRegion(
        groupId: root.menuController,
        consumeOutsideTaps: root.isOpen && widget.consumeOutsideTaps,
        onTapOutside: handleOutsideTap,

Review comment (suggestion):
```suggestion
    // Transform the anchor rectangle corners using the full transform matrix.
```

Code after:
  }

  @override
  void handleCloseRequest() {
    // Changes in MediaQuery.sizeOf(context) cause RawMenuAnchor to close during
    // didChangeDependencies. When this happens, calling setState during the
    // closing sequence (handleCloseRequest -> onCloseRequested -> hideOverlay)
    // will throw an error, since we'd be scheduling a build during a build. We
    // avoid this by checking if we're in a build, and if so, we schedule the
    // close for the next frame.
    if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.persistentCallbacks) {
      widget.onCloseRequested(close);
    } else {
      SchedulerBinding.instance.addPostFrameCallback((_) {
        if (mounted) {
          widget.onCloseRequested(close);
        }
      }, debugLabel: 'RawMenuAnchor.handleCloseRequest');
    }
  }

  Widget _buildOverlay(BuildContext context, OverlayChildLayoutInfo layoutInfo) {
    final Matrix4 transform = layoutInfo.childPaintTransform;
    final Size anchorSize = layoutInfo.childSize;

    // Transform the anchor rectangle using the full transform matrix.
    final Rect anchorRect = MatrixUtils.transformRect(transform, Offset.zero & anchorSize);

    final RawMenuOverlayInfo info = RawMenuOverlayInfo(
      anchorRect: anchorRect,
      overlaySize: layoutInfo.overlaySize,
      position: _menuPosition,
      tapRegionGroupId: root.menuController,
    );

    return widget.overlayBuilder(context, info);
  }

  @override
  Widget buildAnchor(BuildContext context) {
    final Widget child = Shortcuts(
      includeSemantics: false,
      shortcuts: _kMenuTraversalShortcuts,
      child: TapRegion(
        groupId: root.menuController,
        consumeOutsideTaps: root.isOpen && widget.consumeOutsideTaps,
        onTapOutside: handleOutsideTap,
        child: Builder(
          key: _anchorKey,
          builder: (BuildContext context) {
            return widget.builder?.call(context, menuController, widget.child) ??