getColumBreakpointIndexes static method

List<List<int>> getColumBreakpointIndexes({
  1. required BSColumn column,
})

gets the breakpoint label indexes of a column, and the width factor of each breakpoint in the column breakpoint

Implementation

static List<List<int>> getColumBreakpointIndexes({
  required BSColumn column,
}) {
  List<List<int>> indexes = [];
  // col- check RegExp
  RegExp colDashCheck = RegExp(r"(^col-)([0-9]|1[0-2])$");

  for (int i = 0; i < column.breakPoints.length; i++) {
    // ensure the current column breakpoint is lowercase
    String currentBreakPoint = column.breakPoints[i].toLowerCase();

    // check for col-
    if (colDashCheck.hasMatch(
      currentBreakPoint,
    )) {
      indexes.add(
        [
          BSBreakPointLabels.values.length - 1,
          int.parse(
            currentBreakPoint.replaceAll(
              RegExp('[^0-9]'),
              '',
            ),
          ),
        ],
      );
      continue;
    }

    // add all others, check for xl match in xxl also
    indexes.add(
      [
        BSBreakPointLabels.values.indexWhere((element) {
          if (currentBreakPoint.contains(
                element.name,
              ) &&
              !(element.name == BSBreakPointLabels.xl.name &&
                  currentBreakPoint == BSBreakPointLabels.xxl.name)) {
            return true;
          }
          return false;
        }),
        int.parse(
          currentBreakPoint.replaceAll(
            RegExp('[^0-9]'),
            '',
          ),
        ),
      ],
    );
  }

  // sort xxl to col
  indexes.sort(
    (a, b) {
      return a[0] - b[0];
    },
  );

  return indexes;
}