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 = QRVersion.auto,
int errorCorrectionLevel = QRErrorCorrectLevel.L,
}) {
late final QRCodeGenerate qrCode;
try {
if (version != QRVersion.auto) {
qrCode = QRCodeGenerate(version, errorCorrectionLevel);
qrCode.addData(data);
} else {
qrCode = QRCodeGenerate.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);
}
}