verifyBytes method

  1. @override
void verifyBytes(
  1. Uint8List data
)
override

Check if the Barcode is valid. Throws BarcodeException with a proper message in case of error

Implementation

@override
void verifyBytes(Uint8List data) {
  if (explicitStartStop) {
    const validStartStop = [0x41, 0x42, 0x43, 0x44, 0x4e, 0x54, 0x2a, 0x45];

    if (data.length < 3) {
      throw BarcodeException(
          'Unable to encode $name Barcode: missing start and/or stop chars');
    }

    if (!validStartStop.contains(data[0])) {
      throw BarcodeException(
          'Unable to encode $name Barcode: "${String.fromCharCode(data[0])}" is an invalid start char');
    }

    if (!validStartStop.contains(data[data.length - 1])) {
      throw BarcodeException(
          'Unable to encode $name Barcode: "${String.fromCharCode(data[data.length - 1])}" is an invalid start char');
    }

    data = data.sublist(1, data.length - 1);
  }

  super.verifyBytes(data);
}