@@ -159,10 +159,9 @@ class _AppState extends State<App> {
159
159
if (state.dynamicAccentColor &&
160
160
lightDynamic != null &&
161
161
darkDynamic != null ) {
162
- // On Android S+ devices, use the provided dynamic color scheme.
163
- // (Recommended) Harmonize the dynamic color scheme' built-in semantic colors.
164
- lightColorScheme = lightDynamic.harmonized ();
165
- darkColorScheme = darkDynamic.harmonized ();
162
+ (lightColorScheme, darkColorScheme) =
163
+ _generateDynamicColourSchemes (
164
+ lightDynamic, darkDynamic);
166
165
} else if (state.accentColor != null ) {
167
166
lightColorScheme =
168
167
ColorScheme .fromSeed (seedColor: state.accentColor! );
@@ -255,4 +254,45 @@ class _AppState extends State<App> {
255
254
});
256
255
}
257
256
}
257
+
258
+ // TODO: Remove this once https://github.com/material-foundation/flutter-packages/pull/599 is merged
259
+ (ColorScheme light, ColorScheme dark) _generateDynamicColourSchemes (
260
+ ColorScheme lightDynamic, ColorScheme darkDynamic) {
261
+ var lightBase = ColorScheme .fromSeed (seedColor: lightDynamic.primary);
262
+ var darkBase = ColorScheme .fromSeed (
263
+ seedColor: darkDynamic.primary, brightness: Brightness .dark);
264
+
265
+ var lightAdditionalColours = _extractAdditionalColours (lightBase);
266
+ var darkAdditionalColours = _extractAdditionalColours (darkBase);
267
+
268
+ var lightScheme =
269
+ _insertAdditionalColours (lightBase, lightAdditionalColours);
270
+ var darkScheme = _insertAdditionalColours (darkBase, darkAdditionalColours);
271
+
272
+ return (lightScheme.harmonized (), darkScheme.harmonized ());
273
+ }
274
+
275
+ List <Color > _extractAdditionalColours (ColorScheme scheme) => [
276
+ scheme.surface,
277
+ scheme.surfaceDim,
278
+ scheme.surfaceBright,
279
+ scheme.surfaceContainerLowest,
280
+ scheme.surfaceContainerLow,
281
+ scheme.surfaceContainer,
282
+ scheme.surfaceContainerHigh,
283
+ scheme.surfaceContainerHighest,
284
+ ];
285
+
286
+ ColorScheme _insertAdditionalColours (
287
+ ColorScheme scheme, List <Color > additionalColours) =>
288
+ scheme.copyWith (
289
+ surface: additionalColours[0 ],
290
+ surfaceDim: additionalColours[1 ],
291
+ surfaceBright: additionalColours[2 ],
292
+ surfaceContainerLowest: additionalColours[3 ],
293
+ surfaceContainerLow: additionalColours[4 ],
294
+ surfaceContainer: additionalColours[5 ],
295
+ surfaceContainerHigh: additionalColours[6 ],
296
+ surfaceContainerHighest: additionalColours[7 ],
297
+ );
258
298
}
0 commit comments