expressionToBorder static method

Border expressionToBorder(
  1. List<Expression?>? borderWidths,
  2. List<LiteralTerm?>? borderStyles,
  3. List<Expression?>? borderColors
)

Implementation

static Border expressionToBorder(List<css.Expression?>? borderWidths, List<css.LiteralTerm?>? borderStyles, List<css.Expression?>? borderColors) {
  CustomBorderSide left = CustomBorderSide();
  CustomBorderSide top = CustomBorderSide();
  CustomBorderSide right = CustomBorderSide();
  CustomBorderSide bottom = CustomBorderSide();
  if (borderWidths != null && borderWidths.isNotEmpty) {
    top.width = expressionToBorderWidth(borderWidths.first);
    if (borderWidths.length == 4) {
      right.width = expressionToBorderWidth(borderWidths[1]);
      bottom.width = expressionToBorderWidth(borderWidths[2]);
      left.width = expressionToBorderWidth(borderWidths.last);
    }
    if (borderWidths.length == 3) {
      left.width = expressionToBorderWidth(borderWidths[1]);
      right.width = expressionToBorderWidth(borderWidths[1]);
      bottom.width = expressionToBorderWidth(borderWidths.last);
    }
    if (borderWidths.length == 2) {
      bottom.width = expressionToBorderWidth(borderWidths.first);
      left.width = expressionToBorderWidth(borderWidths.last);
      right.width = expressionToBorderWidth(borderWidths.last);
    }
    if (borderWidths.length == 1) {
      bottom.width = expressionToBorderWidth(borderWidths.first);
      left.width = expressionToBorderWidth(borderWidths.first);
      right.width = expressionToBorderWidth(borderWidths.first);
    }
  }
  if (borderStyles != null && borderStyles.isNotEmpty) {
    top.style = expressionToBorderStyle(borderStyles.first);
    if (borderStyles.length == 4) {
      right.style = expressionToBorderStyle(borderStyles[1]);
      bottom.style = expressionToBorderStyle(borderStyles[2]);
      left.style = expressionToBorderStyle(borderStyles.last);
    }
    if (borderStyles.length == 3) {
      left.style = expressionToBorderStyle(borderStyles[1]);
      right.style = expressionToBorderStyle(borderStyles[1]);
      bottom.style = expressionToBorderStyle(borderStyles.last);
    }
    if (borderStyles.length == 2) {
      bottom.style = expressionToBorderStyle(borderStyles.first);
      left.style = expressionToBorderStyle(borderStyles.last);
      right.style = expressionToBorderStyle(borderStyles.last);
    }
    if (borderStyles.length == 1) {
      bottom.style = expressionToBorderStyle(borderStyles.first);
      left.style = expressionToBorderStyle(borderStyles.first);
      right.style = expressionToBorderStyle(borderStyles.first);
    }
  }
  if (borderColors != null && borderColors.isNotEmpty) {
    top.color = expressionToColor(borderColors.first);
    if (borderColors.length == 4) {
      right.color = expressionToColor(borderColors[1]);
      bottom.color = expressionToColor(borderColors[2]);
      left.color = expressionToColor(borderColors.last);
    }
    if (borderColors.length == 3) {
      left.color = expressionToColor(borderColors[1]);
      right.color = expressionToColor(borderColors[1]);
      bottom.color = expressionToColor(borderColors.last);
    }
    if (borderColors.length == 2) {
      bottom.color = expressionToColor(borderColors.first);
      left.color = expressionToColor(borderColors.last);
      right.color = expressionToColor(borderColors.last);
    }
    if (borderColors.length == 1) {
      bottom.color = expressionToColor(borderColors.first);
      left.color = expressionToColor(borderColors.first);
      right.color = expressionToColor(borderColors.first);
    }
  }
  return Border(
      top: BorderSide(width: top.width, color: top.color ?? Colors.black, style: top.style),
      right: BorderSide(width: right.width, color: right.color ?? Colors.black, style: right.style),
      bottom: BorderSide(width: bottom.width, color: bottom.color ?? Colors.black, style: bottom.style),
      left: BorderSide(width: left.width, color: left.color ?? Colors.black, style: left.style)
  );
}