decoration static method

Decoration? decoration(
  1. DataSource source,
  2. List<Object> key
)

Returns a Decoration from the specified map.

The type key specifies the kind of decoration.

A type of box creates a BoxDecoration using the keys color (color), image (decorationImage), border (border), borderRadius (borderRadius), boxShadow (a list of boxShadow), gradient (gradient), backgroundBlendMode (an enumValue of BlendMode), and shape (an enumValue of BoxShape), these keys each corresponding to the properties of BoxDecoration with the same name.

A type of flutterLogo creates a FlutterLogoDecoration using the keys color (color, corresponds to FlutterLogoDecoration.textColor), style (enumValue of FlutterLogoStyle, defaults to FlutterLogoStyle.markOnly), and margin (edgeInsets, always with a left-to-right direction), the latter two keys corresponding to the properties of FlutterLogoDecoration with the same name.

A type of shape creates a ShapeDecoration using the keys color (color), image (decorationImage), gradient (gradient), shadows (a list of boxShadow), and shape (shapeBorder), these keys each corresponding to the properties of ShapeDecoration with the same name.

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

Otherwise, returns null.

Implementation

static Decoration? decoration(DataSource source, List<Object> key) {
  final String? type = source.v<String>([...key, 'type']);
  switch (type) {
    case null:
      return null;
    case 'box':
      return BoxDecoration(
        color: color(source, [...key, 'color']),
        image: decorationImage(source, [...key, 'image']),
        border: border(source, [...key, 'border']),
        borderRadius: borderRadius(source, [...key, 'borderRadius']),
        boxShadow: list<BoxShadow>(source, [...key, 'boxShadow'], boxShadow),
        gradient: gradient(source, [...key, 'gradient']),
        backgroundBlendMode: enumValue<BlendMode>(BlendMode.values, source, [...key, 'backgroundBlendMode']),
        shape: enumValue<BoxShape>(BoxShape.values, source, [...key, 'shape']) ?? BoxShape.rectangle,
      );
    case 'flutterLogo':
      return FlutterLogoDecoration(
        textColor: color(source, [...key, 'color']) ?? const Color(0xFF757575),
        style: enumValue<FlutterLogoStyle>(FlutterLogoStyle.values, source, [...key, 'style']) ?? FlutterLogoStyle.markOnly,
        margin: (edgeInsets(source, [...key, 'margin']) ?? EdgeInsets.zero).resolve(TextDirection.ltr),
      );
    case 'shape':
      return ShapeDecoration(
        color: color(source, [...key, 'color']),
        image: decorationImage(source, [...key, 'image']),
        gradient: gradient(source, [...key, 'gradient']),
        shadows: list<BoxShadow>(source, [...key, 'shadows'], boxShadow),
        shape: shapeBorder(source, [...key, 'shape']) ?? const Border(),
      );
    default:
      final ArgumentDecoder<Decoration?>? decoder = decorationDecoders[type];
      if (decoder == null) {
        return null;
      }
      return decoder(source, key);
  }
}