validate static method
Attempt to parse / generate the QR code data and check for any errors. The resulting QrValidationResult object will hold the status of the QR code as well as the generated QR code data.
Implementation
static QrValidationResult validate({
required String data,
int version = QrVersions.auto,
int errorCorrectionLevel = QrErrorCorrectLevel.L,
}) {
late final QrCode qrCode;
try {
if (version != QrVersions.auto) {
qrCode = QrCode(version, errorCorrectionLevel);
qrCode.addData(data);
} else {
qrCode = QrCode.fromData(
data: data,
errorCorrectLevel: errorCorrectionLevel,
);
}
return QrValidationResult(
status: QrValidationStatus.valid,
qrCode: qrCode,
);
} on InputTooLongException catch (title) {
return QrValidationResult(
status: QrValidationStatus.contentTooLong,
error: title,
);
} on Exception catch (ex) {
return QrValidationResult(status: QrValidationStatus.error, error: ex);
}
}