decodeBoxBorder static method
Decodes the given value
into a BoxBorder. If the value is null
then null
will be returned.
This accepts two separate types of JSON. If the value
has any of:
"color", "style", "width", then this will apply the border to all sides
using Border.all and passing in the results from decodeBorderSide.
If none of the above attributes are found, this expects a full object that defines all sides as follows:
{
"bottom": <BorderSide>,
"left": <BorderSide>,
"right": <BorderSide>,
"top": <BorderSide>
}
See also:
Implementation
static BoxBorder? decodeBoxBorder(
dynamic value, {
bool validate = true,
}) {
BoxBorder? result;
if (value is BoxBorder) {
result = value;
} else if (value != null) {
if (value['color'] != null ||
value['style'] != null ||
value['width'] != null) {
var side = decodeBorderSide(value)!;
result = Border.all(
color: side.color,
style: side.style,
width: side.width,
);
} else {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/box_border',
value: value,
validate: validate,
));
result = Border(
bottom: decodeBorderSide(
value['bottom'],
validate: false,
) ??
BorderSide.none,
left: decodeBorderSide(
value['left'],
validate: false,
) ??
BorderSide.none,
right: decodeBorderSide(
value['right'],
validate: false,
) ??
BorderSide.none,
top: decodeBorderSide(
value['top'],
validate: false,
) ??
BorderSide.none,
);
}
}
return result;
}