Repository: flutter/flutter
File: packages/flutter/lib/src/material/menu_anchor.dart (Dart)

Code before:
  /// {@macro flutter.material.MenuBar.shortcuts_note}
  final List<Widget> menuChildren;

  /// The widget that this [MenuAnchor] surrounds.
  ///
  /// Typically this is a button used to open the menu by calling
  /// [MenuController.open] on the `controller` passed to the builder.
  ///
  /// If not supplied, then the [MenuAnchor] will be the size that its parent
  /// allocates for it.
  ///
  /// If provided, the builder will be called each time the menu is opened or
  /// closed.
  final MenuAnchorChildBuilder? builder;

  /// The optional child to be passed to the [builder].
  ///
  /// Supply this child if there is a portion of the widget tree built in
  /// [builder] that doesn't depend on the `controller` or `context` supplied to
  /// the [builder]. It will be more efficient, since Flutter doesn't then need
  /// to rebuild this child when those change.
  final Widget? child;

  /// Returns the [MenuController] from the closest [MenuAnchor] ancestor.
  ///
  /// If there is no ancestor [MenuAnchor] widget in the tree, this will throw a
  /// [FlutterError].
  ///
  /// See also:
  ///
  ///  * [maybeOf], which is similar to this method, but returns null if
  ///    no [MenuAnchor] ancestor is found.
  static MenuController of(BuildContext context) {
    final MenuController? result = MenuAnchor.maybeOf(context);
    assert(() {
      if (result == null) {
        throw FlutterError(
          'MenuAnchor.of() was called with a context that does not contain a MenuAnchor widget.\n'
          'No MenuAnchor widget ancestor could be found starting from the context that was passed to '
          'MenuAnchor.of().\n'
          'The context used was:\n'
          '  $context',
        );
      }
      return true;
    }());
    return result!;
  }

  /// Returns the [MenuController] from the closest [MenuAnchor] ancestor,
  /// or null if there is no ancestor [MenuAnchor] widget in the tree.

Review comment (bug):
Can we update this statement? Because in release mode, this will not throw a FlutterError.

For example, from the MediaQuery.of() docs:

```
If there is no MediaQuery in scope, this method will throw a TypeError exception in release builds, and throw a descriptive FlutterError in debug builds.
```

Code after:
  final bool useRootOverlay;

  /// A list of children containing the menu items that are the contents of the
  /// menu surrounded by this [MenuAnchor].
  ///
  /// {@macro flutter.material.MenuBar.shortcuts_note}
  final List<Widget> menuChildren;

  /// The widget that this [MenuAnchor] surrounds.
  ///
  /// Typically this is a button used to open the menu by calling
  /// [MenuController.open] on the `controller` passed to the builder.
  ///
  /// If not supplied, then the [MenuAnchor] will be the size that its parent
  /// allocates for it.
  ///
  /// If provided, the builder will be called each time the menu is opened or
  /// closed.
  final MenuAnchorChildBuilder? builder;

  /// The optional child to be passed to the [builder].
  ///
  /// Supply this child if there is a portion of the widget tree built in
  /// [builder] that doesn't depend on the `controller` or `context` supplied to
  /// the [builder]. It will be more efficient, since Flutter doesn't then need
  /// to rebuild this child when those change.
  final Widget? child;

  @override
  State<MenuAnchor> createState() => _MenuAnchorState();

  @override
  List<DiagnosticsNode> debugDescribeChildren() {
    return menuChildren.map<DiagnosticsNode>((Widget child) => child.toDiagnosticsNode()).toList();
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(
      FlagProperty('anchorTapClosesMenu', value: anchorTapClosesMenu, ifTrue: 'AUTO-CLOSE'),
    );
    properties.add(DiagnosticsProperty<FocusNode?>('focusNode', childFocusNode));
    properties.add(DiagnosticsProperty<MenuStyle?>('style', style));
    properties.add(EnumProperty<Clip>('clipBehavior', clipBehavior));
    properties.add(DiagnosticsProperty<Offset?>('alignmentOffset', alignmentOffset));
  }
}

class _MenuAnchorState extends State<MenuAnchor> {
  Axis get _orientation => Axis.vertical;