AppBar theme color parameter deprecation
Summary
#The color parameter in AppBarTheme and AppBarThemeData constructors
and their copyWith methods have been deprecated. Use backgroundColor
instead. This change affects how AppBar themes are configured and might
cause deprecation warnings in existing code.
Background
#The AppBar theming system had two parameters that controlled the same
property: color and backgroundColor. This duplication created confusion
and inconsistency in the API. To improve clarity and consistency, the
color parameter has been deprecated in favor of backgroundColor.
The deprecation affects the following classes and methods:
AppBarThemeconstructorAppBarTheme.copyWithmethodAppBarThemeDataconstructorAppBarThemeData.copyWithmethod
When using the deprecated color parameter, you'll see warnings like:
'color' is deprecated and shouldn't be used. Use backgroundColor instead.
This feature was deprecated after v3.33.0-0.2.pre.The classes also include assertion checks to prevent using both parameters simultaneously:
The color and backgroundColor parameters mean the same thing. Only specify one.Migration guide
#Replace all uses of the color parameter with backgroundColor in
AppBarTheme and AppBarThemeData constructors and copyWith methods.
Code before migration:
// AppBarTheme constructor
AppBarTheme(
color: Colors.blue,
elevation: 4.0,
)
// AppBarTheme copyWith
theme.copyWith(
color: Colors.red,
elevation: 2.0,
)
// AppBarThemeData constructor
AppBarThemeData(
color: Colors.green,
elevation: 4.0,
)
// AppBarThemeData copyWith
themeData.copyWith(
color: Colors.purple,
elevation: 2.0,
)Code after migration:
// AppBarTheme constructor
AppBarTheme(
backgroundColor: Colors.blue,
elevation: 4.0,
)
// AppBarTheme copyWith
theme.copyWith(
backgroundColor: Colors.red,
elevation: 2.0,
)
// AppBarThemeData constructor
AppBarThemeData(
backgroundColor: Colors.green,
elevation: 4.0,
)
// AppBarThemeData copyWith
themeData.copyWith(
backgroundColor: Colors.purple,
elevation: 2.0,
)Timeline
#Landed in version: 3.33.0-0.2.pre
In stable release: 3.35.4
References
#API documentation:
Relevant PRs:
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-10-07。 查看文档源码 或者 为本页面内容提出建议.