colorFilter static method

ColorFilter? colorFilter(
  1. DataSource source,
  2. List<Object> key
)

Returns a ColorFilter from the specified map.

The type key specifies the kind of filter.

A type of linearToSrgbGamma creates a ColorFilter.linearToSrgbGamma.

A type of matrix creates a ColorFilter.matrix, parsing the matrix key as per colorMatrix). If there is no matrix key, returns null.

A type of mode creates a ColorFilter.mode, using the color key (seecolor, defaults to black) and the blendMode key (see enumValue for BlendMdoe, defaults to BlendMode.srcOver)

A type of srgbToLinearGamma creates a ColorFilter.srgbToLinearGamma.

If the type is none of these, but is not null, then the type is looked up in colorFilterDecoders, and if an entry is found, this method defers to that callback.

Otherwise, returns null.

Implementation

static ColorFilter? colorFilter(DataSource source, List<Object> key) {
  final String? type = source.v<String>([...key, 'type']);
  switch (type) {
    case null:
      return null;
    case 'linearToSrgbGamma':
      return const ColorFilter.linearToSrgbGamma();
    case 'matrix':
      final List<double>? matrix = colorMatrix(source, [...key, 'matrix']);
      if (matrix == null) {
        return null;
      }
      return ColorFilter.matrix(matrix);
    case 'mode':
      return ColorFilter.mode(
        color(source, [...key, 'color']) ?? const Color(0xFF000000),
        enumValue<BlendMode>(BlendMode.values, source, [...key, 'blendMode']) ?? BlendMode.srcOver,
      );
    case 'srgbToLinearGamma':
      return const ColorFilter.srgbToLinearGamma();
    default:
      final ArgumentDecoder<ColorFilter?>? decoder = colorFilterDecoders[type];
      if (decoder == null) {
        return null;
      }
      return decoder(source, key);
  }
}