Flutter - Getting Seed colors back from Tonal Palette M3

507 views Asked by At

M3 colorscheme provides all properties like, primary, onPrimary, secondary, onSecondary etc, but they are generally not exactly the same from the colors they are generated from, i.e., the generated colors are different from the seed values.

For Example

TonalPallete of 0064ff as primary color will be changed to 0054d8 or somewhat similiar.

This is how I am getting a palette from the color

  TonalPalette get tonalPalette {
    final cam16 = Cam16.fromInt(value);
    return TonalPalette.of(cam16.hue, cam16.chroma);
  }

This extension creates Palette which can be used to create the colorScheme (primary40 for primary, primary100 for onPrimary, primary90 for primaryContainer etc.)

For Reference :

M3

Real Question :

I need to generate the Seed color from the TonalPallete colors, Kind of backtracking the original/seed color from the generated tonal primary color. Anyway we can do it. Thanks.

Edit : Just to let you know, I dont have a TonalPalette as the object but only its values.

1

There are 1 answers

0
Sahdeep Singh On

Got to know something from the friend and he stated

A color consists of chroma, hue, and luminosity. we're intentionally losing the luminosity of the color to generate the tonal palette which is information lost. Since there is no way other than magic to get that value back, it's impossible to trace back to the seed color

What we know for sure, is that the seed color will have the same hue and chroma, but some luminosity that we don't know of.

So we actually can't have it back :(