QRCode constructor
QRCode(
- String text,
- QRSize size,
- QRCorrection level
Implementation
QRCode(String text, QRSize size, QRCorrection level) {
// FN 167. QR Code: Set the size of module
// pL pH cn fn n
bytes += cQrHeader.codeUnits + [0x03, 0x00, 0x31, 0x43] + [size.value];
// FN 169. QR Code: Select the error correction level
// pL pH cn fn n
bytes += cQrHeader.codeUnits + [0x03, 0x00, 0x31, 0x45] + [level.value];
// FN 180. QR Code: Store the data in the symbol storage area
// FIX #5: utf8.encode soporta cualquier carácter (URLs con tilde, emoji,
// etc.). La versión anterior usaba latin1.encode y tiraba ArgumentError
// ante cualquier carácter fuera de 0x00-0xFF.
final List<int> textBytes = utf8.encode(text);
// FIX #4: pL = (len + 3) & 0xFF, pH = ((len + 3) >> 8) & 0xFF.
// La versión anterior hardcodeaba pH = 0x00 y ponía textBytes.length + 3
// en pL → overflow silencioso para payloads > 252 bytes (URLs largas de
// ARCA, links con muchos parámetros, etc.).
final int storeLen = textBytes.length + 3;
final int storePL = storeLen & 0xFF;
final int storePH = (storeLen >> 8) & 0xFF;
// pL pH cn fn m
bytes += cQrHeader.codeUnits + [storePL, storePH, 0x31, 0x50, 0x30];
bytes += textBytes;
// FN 182. QR Code: Transmit the size information of the symbol data in the symbol storage area
// pL pH cn fn m
bytes += cQrHeader.codeUnits + [0x03, 0x00, 0x31, 0x52, 0x30];
// FN 181. QR Code: Print the symbol data in the symbol storage area
// pL pH cn fn m
bytes += cQrHeader.codeUnits + [0x03, 0x00, 0x31, 0x51, 0x30];
}