shapeBorder static method
Returns a ShapeBorder from the specified map or list.
If the key identifies a list, then each entry in the list is decoded by
recursively invoking shapeBorder, and the result is the combination of
those ShapeBorder values as obtained using the ShapeBorder.+ operator.
Otherwise, if the key identifies a map with a type value, the map is
interpreted according to the type as follows:
-
box: the map'ssideskey is interpreted as a list by border and the resulting BoxBorder (actually, BorderDirectional) is returned. -
beveled: a BeveledRectangleBorder is returned; thesidekey is interpreted by borderSide to set the BeveledRectangleBorder.side (default of [BorderSide.none)), and theborderRadiuskey is interpreted by borderRadius to set the BeveledRectangleBorder.borderRadius (default BorderRadius.zero). -
circle: a CircleBorder is returned; thesidekey is interpreted by borderSide to set the BeveledRectangleBorder.side (default of [BorderSide.none)). -
continuous: a ContinuousRectangleBorder is returned; thesidekey is interpreted by borderSide to set the BeveledRectangleBorder.side (default of [BorderSide.none)), and theborderRadiuskey is interpreted by borderRadius to set the BeveledRectangleBorder.borderRadius (default BorderRadius.zero). -
rounded: a RoundedRectangleBorder is returned; thesidekey is interpreted by borderSide to set the BeveledRectangleBorder.side (default of [BorderSide.none)), and theborderRadiuskey is interpreted by borderRadius to set the BeveledRectangleBorder.borderRadius (default BorderRadius.zero). -
stadium: a StadiumBorder is returned; thesidekey is interpreted by borderSide to set the BeveledRectangleBorder.side (default of [BorderSide.none)).
If the type is none of these, then the type is looked up in
shapeBorderDecoders, and if an entry is found, this method defers to
that callback.
Otherwise, if type is null or is not found in shapeBorderDecoders, returns null.
Implementation
static Map<String, dynamic>? shapeBorder(ShapeBorder? shapeBorder) {
if (shapeBorder == null) return null;
switch (shapeBorder) {
case Border():
return NotNullMap.from({
'type': 'box',
'sides': border(shapeBorder),
});
case BeveledRectangleBorder():
return NotNullMap.from({
'type': 'beveled',
'side': borderSide(shapeBorder.side),
'borderRadius': borderRadius(shapeBorder.borderRadius),
});
case CircleBorder():
return NotNullMap.from(
{'type': 'circle', 'side': borderSide(shapeBorder.side)});
case ContinuousRectangleBorder():
return NotNullMap.from({
'type': 'continuous',
'size': borderSide(shapeBorder.side),
'borderRadius': borderRadius(shapeBorder.borderRadius)
});
case StadiumBorder():
return NotNullMap.from(
{'type': 'stadium', 'side': borderSide(shapeBorder.side)});
default:
final encoder = shapeBorderEncoders[shapeBorder.runtimeType];
if (encoder == null) return null;
return encoder(shapeBorder);
}
}