printQRCodeToTerminal static method
Prints a QR code for the given data to the terminal as ASCII
size
controls the QR version (1-10, default 4, smaller = smaller QR)
Implementation
static void printQRCodeToTerminal(String data, {int size = 4}) {
try {
final typeNumber = size.clamp(1, 10);
final qrCode = QrCode(typeNumber, QrErrorCorrectLevel.L)..addData(data);
final qrImage = QrImage(qrCode);
final int moduleCount = qrImage.moduleCount;
print('\nπ± QR Code for: $data');
print('β${'β' * (moduleCount * 2)}β');
for (int y = 0; y < moduleCount; y++) {
final buffer = StringBuffer('β');
for (int x = 0; x < moduleCount; x++) {
buffer.write(qrImage.isDark(y, x) ? 'ββ' : ' ');
}
buffer.write('β');
print(buffer.toString());
}
print('β${'β' * (moduleCount * 2)}β');
print('π± Scan this QR code with your mobile device');
} catch (e) {
print('β Failed to generate QR code for terminal: $e');
}
}