decodeColorFilter static method
Decodes a dynamic value into a ColorFilter. The schema this requires depends on the type.
Type: matrix
{
matrix: "<List<double>"
}
Type: mode
{
blendMode: "<BlendMode>",
color: "<Color>"
}
Neither type of linearToSrgbGamma
or srgbToLinearGamma
requires any
additional properties.
Implementation
static ColorFilter? decodeColorFilter(
dynamic value, {
bool validate = true,
}) {
ColorFilter? result;
if (value is ColorFilter) {
result = value;
} else if (value != null) {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/color_filter',
value: value,
validate: validate,
));
final type = value['type']?.toString();
switch (type) {
case 'linearToSrgbGamma':
result = const ColorFilter.linearToSrgbGamma();
break;
case 'matrix':
result = ColorFilter.matrix(
JsonClass.maybeParseDoubleList(value['matrix'])!,
);
break;
case 'mode':
result = ColorFilter.mode(
decodeColor(value['color'])!,
decodeBlendMode(value['blendMode']) ?? BlendMode.srcIn,
);
break;
case 'srgbToLinearGamma':
result = const ColorFilter.srgbToLinearGamma();
break;
default:
throw Exception('Unknown ColorFilter type: [$type]');
}
}
return result;
}