hashMapConvertor method

Future<HashMap> hashMapConvertor(
  1. {@required List<String> refList,
  2. @required String csvPath,
  3. String delimiter}
)

Implementation

Future<HashMap> hashMapConvertor(
    {@required List<String> refList,
    @required String csvPath,
    String delimiter}) async {
  String refDelimiter = ",";
  HashMap tempHashMap = new HashMap();

  if (delimiter != null) {
    refDelimiter = delimiter;
  }
  refList.forEach((element) {
    tempHashMap.putIfAbsent(element, () => new List<dynamic>());
  });

  final sData = await rootBundle.loadString(csvPath);
  List lineList = splitLines(sData);
  List dataList = lineList.toString().split(refDelimiter);
  for (int i = refList.length; i < dataList.length; i++) {
    int modValue = i % (refList.length);
    List<dynamic> tempList = tempHashMap[refList[modValue]];
    tempList.add(dataList[i]);
    tempHashMap.update(refList[modValue], (value) => tempList);
  }
  return tempHashMap;
}