Skip to content

Commit 70d5b34

Browse files
authored
Fix missing dynamic ColorScheme surface roles (#690)
* Fix missing dynamic ColorScheme surface roles Update `CorePalette.toColorScheme` to start from `ColorScheme.fromSeed` and then override with dynamic palette values, ensuring all newer surface-related roles are populated correctly (including `surfaceVariant` and `surfaceTint`). Add regression tests for light and dark schemes, adjust the example widget test to assert the seeded primary color, and document the fix in the changelog with linked issues. * x * Document and test ColorScheme role preservation Add explanatory comments clarifying why the conversion uses ColorScheme.fromSeed but overrides with legacy Scheme roles. Add test to verify that primary, onPrimary, primaryContainer, onPrimaryContainer, surface, surfaceVariant, and surfaceTint roles are correctly preserved from the Scheme API in both light and dark modes. * x * Update CHANGELOG.md * Standardize dynamic_color changelog format Reformat the changelog to follow a Keep a Changelog style by adding the top-level header and format note, normalizing section spacing throughout historical entries, and updating the 1.9.0 release date to 2025-08-07. * Update pubspec.lock
1 parent 27a1764 commit 70d5b34

5 files changed

Lines changed: 198 additions & 14 deletions

File tree

packages/dynamic_color/CHANGELOG.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
## 1.9.0 - 2025-08-04
1+
# Changelog
2+
3+
- Populate the missing `ColorScheme` surface roles so dynamic color schemes render correctly ([#574](https://github.com/material-foundation/flutter-packages/issues/574), [#582](https://github.com/material-foundation/flutter-packages/issues/582), [#649](https://github.com/material-foundation/flutter-packages/issues/649))
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## 1.9.0 - 2025-08-07
9+
10+
### Fixed
11+
12+
- Populate the missing `ColorScheme` surface roles so dynamic color schemes render correctly ([#574](https://github.com/material-foundation/flutter-packages/issues/574), [#582](https://github.com/material-foundation/flutter-packages/issues/582), [#649](https://github.com/material-foundation/flutter-packages/issues/649))
13+
214
### Added
15+
316
- Add support for AGP 9
417

518
### Changed
19+
620
- Migrate to Kotlin DSL in Android
721
- Update `compileSdk` to `flutter.compileSdkVersion`
822
- Update `minSdk` to `24`
@@ -11,141 +25,200 @@
1125
- Update testing docs and examples to use `package:dynamic_color_testing/dynamic_color_testing.dart`
1226

1327
## 1.8.1 - 2025-08-01
28+
1429
### Fixed
30+
1531
- Revert moving flutter_test to dev_dependencies
1632

1733
## 1.8.0 - 2025-08-01
34+
1835
### Changed
36+
1937
- Update `material_color_utilities` upper constraint to `0.13.0`
2038
- Update other dependencies
2139
- Update `compileSdkVersion` to `34`
2240
- Fix lints
2341
- Add Swift Package Manager compatibility [\#633](https://github.com/material-foundation/flutter-packages/issues/633).
2442

2543
### Fixed
44+
2645
- Move flutter_test to dev_dependencies
2746

2847
## 1.7.0 - 2024-03-01
48+
2949
### Changed
50+
3051
- Update `material_color_utilities` to `0.8.0`
3152

3253
## 1.6.9 - 2023-12-16
54+
3355
### Changed
56+
3457
- Use `DynamicColors.isDynamicColorAvailable` from `com.google.android.material:material` to verify if dynamic colors are available on Android
3558

3659
## 1.6.8 - 2023-10-17
60+
3761
### Changed
62+
3863
- Broaden constraint for `material_color_utilities` to support it until its `1.0.0` release
3964

4065
## 1.6.7 - 2023-09-15
66+
4167
### Fixed
68+
4269
- Upgraded dependencies
4370

4471
## 1.6.6 - 2023-07-04
72+
4573
### Changed
74+
4675
- Improved documentation for content-based color schemes
4776

4877
## 1.6.5 - 2023-05-15
78+
4979
### Changed
80+
5081
- Broaden constraint for `material_color_utilities` to support multiple Flutter SDK versions
5182

5283
## 1.6.4 - 2023-05-05
84+
5385
### Changed
86+
5487
- Update constraint for `material_color_utilities` to `0.5.0`
5588

5689
## 1.6.3 - 2023-04-04
90+
5791
### Changed
92+
5893
- Update constraint for `material_color_utilities` to `0.3.0`
5994

6095
## 1.6.2 - 2023-02-03
96+
6197
### Added
98+
6299
- Added screenshots
63100

64101
## 1.6.1 - 2023-02-03
102+
65103
### Changed
104+
66105
- Update pubspec `repository`
67106

68107
## 1.6.0 - 2023-01-31
108+
69109
### Added
110+
70111
- Add support for `outlineVariant` and `scrim` colors
71112

72113
### Changed
114+
73115
- Update constraint for `material_color_utilities` to `0.2.0`
74116
- Update Flutter constraint
75117
- Make return value of toColorScheme extension method non-nullable ([\#55](https://github.com/material-foundation/material-dynamic-color-flutter/pull/55))
76118

77119
## 1.5.4 - 2022-09-02
120+
78121
### Changed
122+
79123
- Update constraint for Flutter SDK
80124

81125
## 1.5.3 - 2022-08-09
126+
82127
### Changed
128+
83129
- Update constraint for `material_color_utilities`
84130

85131
## 1.5.2 - 2022-08-02
132+
86133
### Added
134+
87135
- Add support for DWM/Windows Aero's color ([\#50](https://github.com/material-foundation/material-dynamic-color-flutter/pull/50))
88136
- Add support for GTK's accent color on Linux ([\#47](https://github.com/material-foundation/material-dynamic-color-flutter/pull/47))
89137
- Add example tests
90138

91139
### Changed
140+
92141
- Expand and improve README
93142
- Rename `DynamicColorTestingUtils.setMockDynamicColors`'s argument `colorPalette` to `corePalette`
94143
- Improve `DynamicColorBuilder` short-circuiting logic if dynamic color is detected
95144
- Tweak debugging messages
96145

97146
## 1.4.0 - 2022-05-31
147+
98148
### Added
149+
99150
- Add support for Windows' accent color ([\#43](https://github.com/material-foundation/material-dynamic-color-flutter/pull/43))
100151

101152
### Changed
153+
102154
- Rename `DynamicColorPlugin.getControlAccentColor` to `DynamicColorPlugin.getAccentColor`
103155
- Rename `DynamicColorTestingUtils.setMockDynamicColors`'s argument `controlAccentColor` to `accentColor`
104156

105157
## 1.3.0 - 2022-05-25
158+
106159
### Added
160+
107161
- Add support for macOS' control accent color ([\#42](https://github.com/material-foundation/material-dynamic-color-flutter/pull/42))
108162
- Rename `DynamicColorTestingUtils.setMockDynamicColors`'s argument `colors` to `colorPalette`
109163

110164
## 1.2.3 - 2022-05-23
165+
111166
### Changed
167+
112168
- Tweak pubspec description
113169

114170
## 1.2.2 - 2022-04-25
171+
115172
### Changed
173+
116174
- Update lower Flutter SDK bound
117175

118176
## 1.2.0 - 2022-03-24
177+
119178
### Changed
179+
120180
- Improve examples: show how to create dynamic and fallback color schemes, and use harmonization for color schemes and custom colors
121181

122182
## 1.1.2 - 2022-02-15
183+
123184
### Changed
185+
124186
- Move samples to their own library
125187

126188
## 1.1.1 - 2022-02-14
189+
127190
### Changed
191+
128192
- Provide sample `CorePalette`s and corresponding `ColorScheme`s to test utils
129193
- Make the extension method which converts a `CorePalette` to a `ColorScheme` public
130194

131195
## 1.1.0 - 2022-02-08
196+
132197
### Changed
198+
133199
- Qualify builder parameters (`light` => `lightDynamic`, `dark` => `darkDynamic`) for clarity
134200

135201
## 1.0.1 - 2022-02-02
202+
136203
### Changed
204+
137205
- Polish README and examples
138206

139207
## 1.0.0 - 2022-02-02
208+
140209
### Added
210+
141211
- Add missing semantic colors to harmonization from updated m3 color scheme
142212

143213
### Changed
214+
144215
- `DynamicColorBuilder`'s `builder` now provides a light and dark `ColorScheme` rather than a `CorePalette`
145216
- Advanced users can still obtain the palette with `DynamicColorPlugin.getCorePalette()`
146217

147218
## 0.1.0 - 2021-10-29
219+
148220
### Added
221+
149222
- Create `CorePalette` and `TonalPalette` classes
150223
- Create `DynamicColorPlugin` plugin
151224
- Create convenience `DynamicColorBuilder` widget

packages/dynamic_color/example/test/widget_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void main() {
4040
DynamicColorTestingUtils.setMockDynamicColors(
4141
accentColor: Colors.green,
4242
);
43+
final expectedColor = ColorScheme.fromSeed(
44+
seedColor: Colors.green,
45+
).primary;
4346

4447
await tester.pumpWidget(
4548
DynamicColorBuilder(
@@ -52,7 +55,7 @@ void main() {
5255
await tester.pumpAndSettle();
5356

5457
final container = tester.widget<Container>(find.byKey(key));
55-
expect(container.color, const Color(0xff006e1c));
58+
expect(container.color, expectedColor);
5659
});
5760

5861
testWidgets('Verify fallback color is used', (WidgetTester tester) async {

packages/dynamic_color/lib/src/corepalette_to_colorscheme.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ extension CorePaletteToColorScheme on CorePalette {
1616
scheme = Scheme.darkFromCorePalette(this);
1717
break;
1818
}
19-
return ColorScheme(
19+
20+
// Start from seeded values to populate newer ColorScheme roles introduced
21+
// after the legacy Scheme API was defined (for example, surfaceContainer*).
22+
// We then override roles that must stay aligned with the OS-provided dynamic
23+
// palette values from [scheme]. Returning fromSeed directly would drift these
24+
// roles away from Android's dynamic color output.
25+
// TODO(#363): Migrate this conversion to MCU DynamicScheme/CorePalettes so
26+
// all roles can be resolved from one canonical dynamic-color path.
27+
final colorScheme = ColorScheme.fromSeed(
28+
seedColor: Color(scheme.primary),
29+
brightness: brightness,
30+
);
31+
32+
return colorScheme.copyWith(
2033
primary: Color(scheme.primary),
2134
onPrimary: Color(scheme.onPrimary),
2235
primaryContainer: Color(scheme.primaryContainer),
@@ -37,14 +50,14 @@ extension CorePaletteToColorScheme on CorePalette {
3750
outlineVariant: Color(scheme.outlineVariant),
3851
surface: Color(scheme.surface),
3952
onSurface: Color(scheme.onSurface),
40-
surfaceContainerHighest: Color(scheme.surfaceVariant),
53+
surfaceVariant: Color(scheme.surfaceVariant),
4154
onSurfaceVariant: Color(scheme.onSurfaceVariant),
4255
inverseSurface: Color(scheme.inverseSurface),
4356
onInverseSurface: Color(scheme.inverseOnSurface),
4457
inversePrimary: Color(scheme.inversePrimary),
4558
shadow: Color(scheme.shadow),
59+
surfaceTint: Color(scheme.primary),
4660
scrim: Color(scheme.scrim),
47-
brightness: brightness,
4861
);
4962
}
5063
}

packages/dynamic_color/pubspec.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ packages:
175175
dependency: transitive
176176
description:
177177
name: matcher
178-
sha256: "31bd099b47c10cd1aeb55146a2d46ce0277630ecef3f7dae54ad7873f36696cd"
178+
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
179179
url: "https://pub.dev"
180180
source: hosted
181-
version: "0.12.20"
181+
version: "0.12.19"
182182
material_color_utilities:
183183
dependency: "direct main"
184184
description:
@@ -191,10 +191,10 @@ packages:
191191
dependency: "direct dev"
192192
description:
193193
name: meta
194-
sha256: "307249ce4ff29d58a18e97f6345f539382eb9c9c29ecda628900f31de0443dd9"
194+
sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
195195
url: "https://pub.dev"
196196
source: hosted
197-
version: "1.19.0"
197+
version: "1.18.0"
198198
path:
199199
dependency: transitive
200200
description:
@@ -276,18 +276,18 @@ packages:
276276
dependency: transitive
277277
description:
278278
name: test_api
279-
sha256: "2a122cbe059f8b610d3a5415f42e255b6c17b1f21eee1d960f31080237fb4f11"
279+
sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e"
280280
url: "https://pub.dev"
281281
source: hosted
282-
version: "0.7.12"
282+
version: "0.7.11"
283283
vector_math:
284284
dependency: transitive
285285
description:
286286
name: vector_math
287-
sha256: f36f9f3be64c6198714492bb455c11056e33e2f85d9a0b676a48301e44fdcf47
287+
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
288288
url: "https://pub.dev"
289289
source: hosted
290-
version: "2.4.2"
290+
version: "2.2.0"
291291
version_manipulation:
292292
dependency: transitive
293293
description:
@@ -313,5 +313,5 @@ packages:
313313
source: hosted
314314
version: "3.1.3"
315315
sdks:
316-
dart: ">=3.11.0-0 <4.0.0"
316+
dart: ">=3.10.0-0 <4.0.0"
317317
flutter: ">=3.18.0-18.0.pre.54"

0 commit comments

Comments
 (0)