# Updated default text styles for menus

> The default text styles for menus are updated to match the Material 3 specification.




:::important
These breaking change docs are accurate, as of the release
under which they are published. Over time, the
workarounds described here might become inaccurate.
We don't, in general, keep these breaking change docs up
to date as of each release.

这些破坏性改动文档的准确性仅限于其发布时对应的版本。
随着时间的推移，文档中描述的方案可能会逐渐失效。
通常情况下，我们不会在每次发布新版本时都对这些文档进行同步更新。

The [breaking change index file](/release/breaking-changes)
lists the docs created for each release.

[破坏性改动列表](/release/breaking-changes) 
列出了每个版本的文档。

:::


## Summary

The default text styles used for menus are updated
to match the Material 3 specification.

## Context

The default text style for `MenuItemButton` (a widget used
in a `MenuBar`, and in a menu created with `MenuAnchor`),
and `DropdownMenuEntry` (in the `DropdownMenu`) is
updated to match the Material 3 specification.

Likewise, the default text style for the `DropdownMenu`s `TextField` is updated
to match the Material 3 specification.

## Description of change

The default text style for `MenuItemButton` (a widget used
in a `MenuBar`, and in a menu created with `MenuAnchor`),
and `DropdownMenuEntry` (in the `DropdownMenu`) is updated from
`TextTheme.bodyLarge` to `TextTheme.labelLarge` for Material 3.

The default text style for the `DropdownMenu`s `TextField` is updated from
`TextTheme.labelLarge` to `TextTheme.bodyLarge` for Material 3.

## Migration guide

A `MenuItemButton` for Material 3 uses
`TextTheme.labelLarge` as the default text style.
To use the previous default text style, set the `TextTheme.bodyLarge` text style
in the `MenuItemButton.style` or `MenuButtonThemeData.style` properties.

Code before migration:

```dart
MenuItemButton(
  child: Text(MenuEntry.about.label),
  onPressed: () => _activate(MenuEntry.about),
),
```

```dart
menuButtonTheme: MenuButtonThemeData(
  style: MenuItemButton.styleFrom(
    /// ...
  ),
),
```

Code after migration:

```dart
MenuItemButton(
  style: MenuItemButton.styleFrom(
    textStyle: Theme.of(context).textTheme.bodyLarge,
  ),
  child: Text(MenuEntry.about.label),
  onPressed: () => _activate(MenuEntry.about),
),
```

```dart
menuButtonTheme: MenuButtonThemeData(
  style: MenuItemButton.styleFrom(
    textStyle: Theme.of(context).textTheme.bodyLarge,
  ),
),
```

A `DropdownMenu`'s `TextField` for Material 3
uses `TextTheme.bodyLarge` as the default text style.
To use the previous default text style,
set the `TextTheme.labelLarge` text style in
the `DropdownMenu.textStyle` or `DropdownMenuThemeData.textStyle` properties.

Code before migration:

```dart
DropdownMenu<ColorLabel>(
  initialSelection: ColorLabel.green,
  controller: colorController,
  label: const Text('Color'),
  dropdownMenuEntries: colorEntries,
  onSelected: (ColorLabel? color) {
    setState(() {
      selectedColor = color;
    });
  },
),
```

```dart
dropdownMenuTheme: DropdownMenuThemeData(
  /// ...
),
```

Code after migration:

```dart
DropdownMenu<ColorLabel>(
  textStyle: Theme.of(context).textTheme.labelLarge,
  initialSelection: ColorLabel.green,
  controller: colorController,
  label: const Text('Color'),
  dropdownMenuEntries: colorEntries,
  onSelected: (ColorLabel? color) {
    setState(() {
      selectedColor = color;
    });
  },
),
```

```dart
dropdownMenuTheme: DropdownMenuThemeData(
  textStyle: TextStyle(
    fontStyle: FontStyle.italic,
    fontWeight: FontWeight.bold,
  ),
),
```

A `DropdownMenu`'s `DropdownMenuEntry` for Material 3
uses `TextTheme.labelLarge` as the default text style.
To use the previous default text style, set the
`TextTheme.bodyLarge` text style in
the `DropdownMenuEntry.style` or `MenuButtonThemeData.style` properties.

Code before migration:

```dart
DropdownMenuEntry<ColorLabel>(
  value: color,
  label: color.label,
),
```

```dart
menuButtonTheme: MenuButtonThemeData(
  style: MenuItemButton.styleFrom(
    /// ...
  ),
),
```

Code after migration:

```dart
DropdownMenuEntry<ColorLabel>(
  style: MenuItemButton.styleFrom(
    textStyle: Theme.of(context).textTheme.bodyLarge,
  ),
  value: color,
  label: color.label,
),
```

```dart
menuButtonTheme: MenuButtonThemeData(
  style: MenuItemButton.styleFrom(
    textStyle: Theme.of(context).textTheme.bodyLarge,
  ),
),
```

## Timeline

Landed in version: 3.14.0-11.0.pre<br>
In stable release: 3.16

## References

API documentation:

* [`MenuBar`][]
* [`MenuAnchor`][]
* [`MenuItemButton`][]
* [`MenuButtonTheme`][]
* [`DropdownMenu`][]
* [`DropdownMenuEntry`][]
* [`DropdownMenuTheme`][]
* [`TextTheme`][]

Relevant PRs:

* [Update default menu text styles for Material 3][]

[`MenuBar`]: https://api.flutter-io.cn/flutter/material/MenuBar-class.html
[`MenuAnchor`]: https://api.flutter-io.cn/flutter/material/MenuAnchor-class.html
[`MenuItemButton`]: https://api.flutter-io.cn/flutter/material/MenuItemButton-class.html
[`MenuButtonTheme`]: https://api.flutter-io.cn/flutter/material/MenuButtonTheme-class.html
[`DropdownMenu`]: https://api.flutter-io.cn/flutter/material/DropdownMenu-class.html
[`DropdownMenuEntry`]: https://api.flutter-io.cn/flutter/material/DropdownMenuEntry-class.html
[`DropdownMenuTheme`]: https://api.flutter-io.cn/flutter/material/DropdownMenuTheme-class.html
[`TextTheme`]: https://api.flutter-io.cn/flutter/material/TextTheme-class.html

[Update default menu text styles for Material 3]: https://github.com/flutter/flutter/pull/131930

