calculateCheckDigit method
Implementation
String calculateCheckDigit() {
int checkSum = 0;
for (int i = 0; i < _formattedData.length; i++) {
//replace apostrophes with double apostrophes for escape chars
var s = _formattedData[i].replaceAll("'", "''");
//try to find value in the A column
var rows = _codes.firstWhere((item) => item!.a == s, orElse: () => null);
//try to find value in the B column
if (rows == null) {
rows = _codes.firstWhere((item) => item!.b == s, orElse: () => null);
}
//try to find value in the C column
if (rows == null) {
rows = _codes.firstWhere((item) => item!.c == s, orElse: () => null);
}
var value = int.parse(rows!.value);
var addition = value * ((i == 0) ? 1 : i);
checkSum += addition;
}
int remainder = (checkSum % 103);
var retRows =
_codes.firstWhere((item) => item!.value == remainder.toString());
return retRows!.encoding;
}