material-foundation / material-color-utilities

Color libraries for Material You
Apache License 2.0
1.67k stars 144 forks source link

How to build a `DynamicScheme` from a `CorePalette`? #148

Open amal-stack opened 5 months ago

amal-stack commented 5 months ago

Earlier, given a CorePalette, the way to generate the Material color roles was to use Scheme.lightFromCorePalette and Scheme.darkFromCorePalette.

Currently, since Scheme is deprecated in favor of DynamicScheme, what is the way to generate a DyanamicScheme or to obtain color roles given a CorePalette? Is the CorePalette class still relevant or will it be deprecated?

I'm currently using the dynamic_color package for Dart that obtains a CorePalette from Android systems using DynamicColorPlugin.getCorePalette. However, the DynamicColorBuilder widget uses Scheme.lightFromCorePalette and Scheme.darkFromCorePalette to create the color roles and maps it to the Flutter ColorScheme. The deprecated Scheme class does not have the new surface roles( like surfaceContainer) and the fixed roles (like primaryFixed). Flutter has added these new roles to the ColorScheme class (in the beta release) but the Scheme methods do not assign these color roles. So, when I use these new roles in my app, their colors are always null.

DynamicColorBuilder (from the dynamic_color package) is a simple widget that calls DynamicColorPlugin.getCorePalette and maps it to a flutter ColorScheme. So, I can write my own implementation until the dynamic_color package is updated to use the new DynamicScheme classes. In the meantime, if I obtain the Android platform's CorePalette using DynamicColorPlugin.getCorePalette, how can I convert it to a DynamicScheme and obtain the color roles from it?