getTableStyle static method

String getTableStyle(
  1. MsTable msTable,
  2. List<Styles> stylesList
)

Function for getting table styles

Implementation

static String getTableStyle(MsTable msTable, List<Styles> stylesList) {
  String tableStyleHtml = "";
  if (msTable.tblStyle.isNotEmpty) {
    Styles? tableStyles = stylesList.firstWhereOrNull((style) {
      return style.styleId == msTable.tblStyle;
    });
    if (tableStyles != null) {
      if (tableStyles.tableBorder.isNotEmpty) {
        String topColor = "";
        String topBrStyle = "solid";
        String topSz = "";
        if (tableStyles.tableBorder["top-val"] != null) {
          topBrStyle = "solid";
        }
        if (tableStyles.tableBorder["top-sz"] != null) {
          topSz = (int.parse(tableStyles.tableBorder["top-sz"]!) / 2).toString();
        }
        if (tableStyles.tableBorder["top-color"] != null && tableStyles.tableBorder["top-color"] != "auto") {
          topColor = "#${tableStyles.tableBorder["top-color"]!}";
        }
        tableStyleHtml = "${tableStyleHtml}border-top: ${topSz}px $topBrStyle $topColor; ";
        String leftColor = "";
        String leftBrStyle = "solid";
        String leftSz = "";
        if (tableStyles.tableBorder["left-val"] != null) {
          leftBrStyle = "solid";
        }
        if (tableStyles.tableBorder["left-sz"] != null) {
          leftSz = (int.parse(tableStyles.tableBorder["left-sz"]!) / 2).toString();
        }
        if (tableStyles.tableBorder["left-color"] != null) {
          leftColor = "#${tableStyles.tableBorder["left-color"]}";
        }
        tableStyleHtml = "${tableStyleHtml}border-left: ${leftSz}px $leftBrStyle $leftColor; ";
        String bottomColor = "";
        String bottomBrStyle = "solid";
        String bottomSz = "";
        if (tableStyles.tableBorder["bottom-val"] != null) {
          bottomBrStyle = "solid";
        }
        if (tableStyles.tableBorder["bottom-sz"] != null) {
          bottomSz = (int.parse(tableStyles.tableBorder["bottom-sz"]!) / 2).toString();
        }
        if (tableStyles.tableBorder["bottom-color"] != null && tableStyles.tableBorder["bottom-color"] != "auto") {
          bottomColor = "#${tableStyles.tableBorder["bottom-color"]}";
        }
        tableStyleHtml = "${tableStyleHtml}border-bottom: ${bottomSz}px $bottomBrStyle $bottomColor; ";
        String rightColor = "";
        String rightBrStyle = "solid";
        String rightSz = "";
        if (tableStyles.tableBorder["right-val"] != null) {
          rightBrStyle = "solid";
        }
        if (tableStyles.tableBorder["right-sz"] != null) {
          rightSz = (int.parse(tableStyles.tableBorder["right-sz"]!) / 2).toString();
        }
        if (tableStyles.tableBorder["right-color"] != null && tableStyles.tableBorder["right-color"] != "auto") {
          rightColor = "#${tableStyles.tableBorder["right-color"]}";
        }
        tableStyleHtml = "${tableStyleHtml}border-right: ${rightSz}px $rightBrStyle $rightColor; ";
      }
    }
  }
  return tableStyleHtml;
}