decoration static method
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 Map<String, dynamic>? decoration(Decoration? decoration) {
if (decoration == null) return null;
if (decoration is BoxDecoration) {
return NotNullMap.from({
'type': 'box',
'color': color(decoration.color),
'image': decorationImage(decoration.image),
'border': border(decoration.border),
'borderRadius': borderRadius(decoration.borderRadius),
'boxShadow': list<BoxShadow, Map<String, dynamic>?>(
decoration.boxShadow, boxShadow),
'gradient': gradient(decoration.gradient),
'backgroundBlendMode':
enumValue<BlendMode>(decoration.backgroundBlendMode),
'shape': enumValue<BoxShape>(decoration.shape),
});
} else if (decoration is FlutterLogoDecoration) {
return NotNullMap.from({
'type': 'flutterLogo',
'color': color(decoration.textColor),
'style': enumValue<FlutterLogoStyle>(decoration.style),
'margin': edgeInsets(decoration.margin),
});
} else if (decoration is ShapeDecoration) {
return NotNullMap.from({
'type': 'shape',
'color': color(decoration.color),
'image': decorationImage(decoration.image),
'gradient': gradient(decoration.gradient),
'shadows': list<BoxShadow, Map<String, dynamic>?>(
decoration.shadows, boxShadow),
'shape': shapeBorder(decoration.shape),
});
}
final encoder = decorationEncoders[decoration.runtimeType];
if (encoder != null) {
return encoder(decoration);
}
return null;
}