decodeMaterialColor static method
Decodes the given value
to an MaterialColor. This expects the
given value
to be of the following structure:
{
"primary": <Color>,
"swatches": <Map<String, Color>
}
See also:
Implementation
static MaterialColor? decodeMaterialColor(
dynamic value, {
bool validate = true,
}) {
MaterialColor? result;
if (value is MaterialColor) {
result = value;
} else if (value != null) {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/material_color',
value: value,
validate: validate,
));
var swatches = <int, Color>{};
var swatchesIn = value['swatches'];
swatchesIn.forEach(
(key, value) =>
swatches[JsonClass.parseInt(key)!] = decodeColor(value)!,
);
result = MaterialColor(
decodeColor(value['primary'])!.value,
swatches,
);
}
return result;
}