getEdgeValues static method
List<String?>?
getEdgeValues(
- String shorthandProperty, {
- bool isLengthOrPercentage = false,
- bool isNonNegativeLengthOrPercentage = false,
- bool isNonNegativeLength = false,
})
Implementation
static List<String?>? getEdgeValues(
String shorthandProperty, {
bool isLengthOrPercentage = false,
bool isNonNegativeLengthOrPercentage = false,
bool isNonNegativeLength = false,
}) {
List<String> properties = _splitBySpace(shorthandProperty);
String? topValue;
String? rightValue;
String? bottomValue;
String? leftValue;
if (properties.length == 1) {
topValue = rightValue = bottomValue = leftValue = properties[0];
} else if (properties.length == 2) {
topValue = bottomValue = properties[0];
leftValue = rightValue = properties[1];
} else if (properties.length == 3) {
topValue = properties[0];
rightValue = leftValue = properties[1];
bottomValue = properties[2];
} else if (properties.length == 4) {
topValue = properties[0];
rightValue = properties[1];
bottomValue = properties[2];
leftValue = properties[3];
}
if (topValue == null || rightValue == null || bottomValue == null || leftValue == null) {
return null;
}
if (isLengthOrPercentage) {
if ((!CSSLength.isLength(topValue) && !CSSPercentage.isPercentage(topValue) && !CSSFunction.isFunction(topValue)) ||
(!CSSLength.isLength(rightValue) && !CSSPercentage.isPercentage(rightValue) && !CSSFunction.isFunction(rightValue)) ||
(!CSSLength.isLength(bottomValue) && !CSSPercentage.isPercentage(bottomValue) && !CSSFunction.isFunction(bottomValue)) ||
(!CSSLength.isLength(leftValue) && !CSSPercentage.isPercentage(leftValue)) && !CSSFunction.isFunction(leftValue)) {
return null;
}
} else if (isNonNegativeLengthOrPercentage) {
if ((!CSSLength.isNonNegativeLength(topValue) && !CSSPercentage.isNonNegativePercentage(topValue) && !CSSFunction.isFunction(topValue)) ||
(!CSSLength.isNonNegativeLength(rightValue) && !CSSPercentage.isNonNegativePercentage(rightValue) && !CSSFunction.isFunction(rightValue)) ||
(!CSSLength.isNonNegativeLength(bottomValue) && !CSSPercentage.isNonNegativePercentage(bottomValue) && !CSSFunction.isFunction(bottomValue)) ||
(!CSSLength.isNonNegativeLength(leftValue) && !CSSPercentage.isNonNegativePercentage(leftValue) && !CSSFunction.isFunction(leftValue))) {
return null;
}
} else if (isNonNegativeLength) {
if ((!CSSLength.isNonNegativeLength(topValue) && !CSSFunction.isFunction(topValue)) ||
(!CSSLength.isNonNegativeLength(rightValue) && !CSSFunction.isFunction(rightValue)) ||
(!CSSLength.isNonNegativeLength(bottomValue) && !CSSFunction.isFunction(bottomValue)) ||
(!CSSLength.isNonNegativeLength(leftValue) && !CSSFunction.isFunction(leftValue))) {
return null;
}
}
// Assume the properties are in the usual order top, right, bottom, left.
return [topValue, rightValue, bottomValue, leftValue];
}