isValidCRC method
Validates whether the CRC value in the QR code data matches the calculated CRC value.
The QR code data is expected to end with a CRC value in the format (63\d{2})([0-9A-Fa-f]{4})$
.
This method extracts the embedded CRC value and compares it with the calculated CRC.
qrData is the input QR code data string that includes the CRC to validate.
Returns:
true
if the CRC values match.false
otherwise.
Implementation
bool isValidCRC() {
final match = RegExp(r'(63\d{2})([0-9A-Fa-f]{4})\$').firstMatch(qrData);
final calculatedCRC = crc.toUpperCase();
return match != null && match.group(2)?.toUpperCase() == calculatedCRC;
}