checkLength method
Check the EAN Barcode length and verify the checksum. if the checksum is omitted, calculate and append it to the data.
Implementation
@protected
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 last = data.substring(length - 1);
    final 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;
}