Skip to content

Add deprecation breaking change for app bar color #12156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/content/release/breaking-changes/appbar-theme-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: AppBar theme color parameter deprecation
description: >-
The color parameter in AppBarTheme and AppBarThemeData has been
deprecated in favor of backgroundColor for better API consistency.
---

## Summary

The `color` parameter in `AppBarTheme` and `AppBarThemeData` constructors
and their `copyWith` methods hasve been deprecated. Use `backgroundColor`
instead. This change affects how AppBar themes are configured and may
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:

- `AppBarTheme` constructor
- `AppBarTheme.copyWith` method
- `AppBarThemeData` constructor
- `AppBarThemeData.copyWith` method

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:

```dart
// 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:

```dart
// 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<br>
In stable release: Not yet

## References

API documentation:

- [`AppBarTheme`](https://main-api.flutter.dev/flutter/material/AppBarTheme-class.html)
- [`AppBarThemeData`](https://main-api.flutter.dev/flutter/material/AppBarThemeData-class.html)

Relevant PRs:

- [AppBar theme color parameter deprecation #170624]({{site.github}}/flutter/flutter/pull/170624)
1 change: 1 addition & 0 deletions src/content/release/breaking-changes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ They're sorted by release and listed in alphabetical order:
* [Component theme normalization updates][]

[Redesigned the Radio Widget]: /release/breaking-changes/radio-api-redesign
[Deprecate app bar color]: /release/breaking-changes/appbar-theme-color
[Removed semantics elevation and thickness]: /release/breaking-changes/remove-semantics-elevation-and-thickness
[Deprecate `TextField.canRequestFocus`]: /release/breaking-changes/can-request-focus
[Stop generating `AssetManifest.json`]: /release/breaking-changes/asset-manifest-dot-json
Expand Down