checkLength method
Implementation
String checkLength(String data, int length) {
if (data.length == length - 1) {
data += checkSumModulo10(data);
} else {
if (data.length != length) {
throw BarcodeException('Unable to encode "$data" to $name Barcode, it is not $length digits');
}
final String last = data.substring(length - 1);
final String checksum = checkSumModulo10(data.substring(0, length - 1));
if (last != checksum) {
throw BarcodeException('Unable to encode "$data" to $name Barcode, checksum "$last" should be "$checksum"');
}
}
return data;
}