fromList static method
Create colors from a fixed-size list of ARGB color ints.
Inverse of TonalPalette.asList.
Implementation
static TonalPalette fromList(List<int> colors) {
assert(colors.length == commonSize);
var cache = <int, int>{};
commonTones.asMap().forEach(
(int index, int toneValue) => cache[toneValue] = colors[index]);
// Approximately deduces the original hue and chroma that generated this
// list of colors.
// Uses the hue and chroma of the provided color with the highest chroma.
var bestHue = 0.0, bestChroma = 0.0;
for (final argb in colors) {
final hct = Hct.fromInt(argb);
// If the color is too close to white, its chroma may have been
// affected by a known issue, so we ignore it.
// https://github.com/material-foundation/material-color-utilities/issues/140
if (hct.tone > 98.0) continue;
if (hct.chroma > bestChroma) {
bestHue = hct.hue;
bestChroma = hct.chroma;
}
}
return TonalPalette._fromCache(cache, bestHue, bestChroma);
}