generateBarcodeCheckSum property
Return a checksum digit for a barcode
Implementation
String get generateBarcodeCheckSum {
if (isNotNumber) {
throw const FormatException('Code is not a number');
}
int i = 0;
int j;
int p = 0;
int t = length;
for (j = 1; j <= t; j++) {
if ((j & ~ -2) == 0) {
p += int.parse(substring(j - 1, j));
} else {
i += int.parse(substring(j - 1, j));
}
}
if (t == 7 || t == 11) {
i = i * 3 + p;
p = (i + 9) ~/ 10 * 10;
t = p - i;
} else {
p = p * 3 + i;
i = (p + 9) ~/ 10 * 10;
t = i - p;
}
return t.toString();
}