Component theme normalization updates
Summary
#AppBarTheme
and BottomAppBarTheme
were refactored to conform to Flutter's conventions for component themes.
AppBarThemeData
and BottomAppBarThemeData
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
appBarTheme
property has been changed fromAppBarTheme
toAppBarThemeData
. - The type of
bottomAppBarTheme
property has been changed fromBottomAppBarTheme
toBottomAppBarThemeData
.
The return type of the component theme xTheme.of()
methods and
Theme.of().xTheme
have also changed to xThemeData
.
Code before migration:
final AppBarTheme appBarTheme = Theme.of(context).appBarTheme;
final AppBarTheme appBarTheme = AppBarTheme.of(context);
final BottomAppBarTheme bottomAppBarTheme = Theme.of(context).bottomAppBarTheme;
final BottomAppBarTheme bottomAppBarTheme = BottomAppBarTheme.of(context);
final ThemeData theme = ThemeData(
appBarTheme: AppBarTheme(),
bottomAppBarTheme: BottomAppBarTheme(),
);
final ThemeData theme = ThemeData().copyWith(
appBarTheme: AppBarTheme(),
bottomAppBarTheme: BottomAppBarTheme(),
);
Code after migration:
final AppBarThemeData appBarTheme = Theme.of(context).appBarTheme;
final AppBarThemeData appBarTheme = AppBarTheme.of(context);
final BottomAppBarThemeData bottomAppBarTheme = Theme.of(context).bottomAppBarTheme;
final BottomAppBarThemeData bottomAppBarTheme = BottomAppBarTheme.of(context);
final ThemeData theme = ThemeData(
appBarTheme: AppBarThemeData(),
bottomAppBarTheme: BottomAppBarThemeData(),
);
final ThemeData theme = ThemeData().copyWith(
appBarTheme: AppBarThemeData(),
bottomAppBarTheme: BottomAppBarThemeData(),
);
Timeline
#Landed in version: Not yet
Stable release: Not yet
References
#API documentation:
Relevant PRs:
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-07-01。 查看文档源码 或者 为本页面内容提出建议.