Skip to content

Commit 2b0a1f8

Browse files
committed
fix: Dynamic color scheme
1 parent acede49 commit 2b0a1f8

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

kitchenowl/lib/app.dart

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ class _AppState extends State<App> {
159159
if (state.dynamicAccentColor &&
160160
lightDynamic != null &&
161161
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);
166165
} else if (state.accentColor != null) {
167166
lightColorScheme =
168167
ColorScheme.fromSeed(seedColor: state.accentColor!);
@@ -255,4 +254,45 @@ class _AppState extends State<App> {
255254
});
256255
}
257256
}
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+
);
258298
}

0 commit comments

Comments
 (0)