# Component theme normalization

> `CardTheme`, `DialogTheme`, and `TabBarTheme` have been normalized to follow Flutter's convention for component themes in the Material library.




:::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

`CardTheme`, `DialogTheme` and `TabBarTheme` were refactored to
conform to Flutter's conventions for component themes.
`CardThemeData`, `DialogThemeData`, and `TabBarThemeData` were added to
define overrides for the defaults of the component visual properties.
Releases of Flutter continue to normalize component themes like these for
a more consistent theming experience in the material library.

## Migration guide

In `ThemeData`:

- The type of the `cardTheme` property has been
  changed from `CardTheme` to `CardThemeData`.
- The type of the `dialogTheme` property has been
  changed from the `DialogTheme` to `DialogThemeData`.
- The type of `tabBarTheme` property has been
  changed from `TabBarTheme` to `TabBarThemeData`.

The return type of the component theme `xTheme.of()` methods and
`Theme.of().xTheme` have also changed to `xThemeData` accordingly.

Code before migration:

```dart
final CardTheme cardTheme = Theme.of(context).cardTheme;
final CardTheme cardTheme = CardTheme.of(context);

final DialogTheme dialogTheme = Theme.of(context).dialogTheme;
final DialogTheme dialogTheme = DialogTheme.of(context);

final TabBarTheme tabBarTheme = Theme.of(context).tabBarTheme;
final TabBarTheme tabBarTheme = TabBarTheme.of(context);
```

Code after migration:

```dart
final CardThemeData cardTheme = Theme.of(context).cardTheme;
final CardThemeData cardTheme = CardTheme.of(context);

final DialogThemeData dialogTheme = Theme.of(context).dialogTheme;
final DialogThemeData dialogTheme = DialogTheme.of(context);

final TabBarThemeData tabBarTheme = Theme.of(context).tabBarTheme;
final TabBarThemeData tabBarTheme = TabBarTheme.of(context);
```

## Timeline

Landed in version: 3.27.0-0.0.pre<br>
Stable release: 3.27

## References

API documentation:

* [`ThemeData`][]
* [`CardTheme`][]
* [`DialogTheme`][]
* [`TabBarTheme`][]

Relevant PRs:

* [Normalize ThemeData.cardTheme][]
* [Normalize ThemeData.dialogTheme][]
* [Normalize ThemeData.tabBarTheme][]

[`ThemeData`]: https://api.flutter-io.cn/flutter/material/ThemeData-class.html
[`CardTheme`]: https://api.flutter-io.cn/flutter/material/CardTheme-class.html
[`DialogTheme`]: https://api.flutter-io.cn/flutter/material/DialogTheme-class.html
[`TabBarTheme`]: https://api.flutter-io.cn/flutter/material/TabBarTheme-class.html
[Normalize ThemeData.cardTheme]: https://github.com/flutter/flutter/pull/153254
[Normalize ThemeData.dialogTheme]: https://github.com/flutter/flutter/pull/155129
[Normalize ThemeData.tabBarTheme]: https://github.com/flutter/flutter/pull/156253

