setComponentsMapping method

void setComponentsMapping(
  1. List<GetComponent> components
)

Sets the components mapping with the provided components.

Implementation

void setComponentsMapping(List<GetComponent> components) {
  List<Map<String, dynamic>> componentsList = [];

  for (var comp in components) {
    final sheet = comp.controllers[0].text;
    final startCol = getStartCol(comp.controllers[1].text);
    // make qpPattern empty if not Class Test
    final qpPattern = sheet != "IA" ? [] : comp.qpAnalyser.analysedData.qpPattern;
    // use the entered question count if qpPattern is empty
    final questionsCount = qpPattern.isEmpty ? int.parse(comp.controllers[2].text) : qpPattern.length;
    debugPrint("$sheet: $questionsCount");
    Map<String, dynamic> controllerMap = {
      "sheet": sheet,
      "questionsCount": questionsCount,
      "qpPattern": qpPattern,
      "startColumn": startCol,
      "mappings": {},
    };
    for (var (i, it) in qpPattern.indexed) {
      final column = getColName(startCol, i);
      controllerMap["mappings"]['${column}7'] = it['Q'].toString();
      controllerMap["mappings"]['${column}8'] = "CO${it['C']}";
      controllerMap["mappings"]['${column}9'] = it['M'].toString();
    }
    componentsList.add(controllerMap);
  }
  cellMappings[Mapping.components] = componentsList;
}