of static method

MenuThemeData of(
  1. BuildContext context
)

Returns the closest instance of this class's data value that encloses the given context. If there is no ancestor, it returns ThemeData.menuTheme.

Typical usage is as follows:

Widget build(BuildContext context) {
  return MenuTheme(
    data: const MenuThemeData(
      style: MenuStyle(
        backgroundColor: MaterialStatePropertyAll<Color>(Colors.red),
      ),
    ),
    child: child,
  );
}

Implementation

static MenuThemeData of(BuildContext context) {
  final MenuTheme? menuTheme = context.dependOnInheritedWidgetOfExactType<MenuTheme>();
  return menuTheme?.data ?? Theme.of(context).menuTheme;
}