generateQrCode function
Implementation
String generateQrCode(
String data, {
int vPadding = 2,
int hPadding = 4,
}) {
final qr = QrCode(
2,
QrErrorCorrectLevel.L,
)..addData(data);
final qrImage = QrImage(qr);
final qrBuffer = StringBuffer();
for (int p = 0; p < vPadding; p++) {
qrBuffer.writeln(whiteWhite * (qrImage.moduleCount + hPadding * 2));
}
for (var row = 0; row < qrImage.moduleCount; row += 2) {
qrBuffer.write(whiteWhite * hPadding);
for (var col = 0; col < qrImage.moduleCount; col++) {
final top = qrImage.isDark(row, col);
final btm =
row + 1 == qrImage.moduleCount ? false : qrImage.isDark(row + 1, col);
if (top && btm)
qrBuffer.write(blackBlack);
else if (top && !btm)
qrBuffer.write(blackWhite);
else if (!top && btm)
qrBuffer.write(whiteBlack);
else if (!top && !btm) qrBuffer.write(whiteWhite);
}
qrBuffer.write(whiteWhite * hPadding);
qrBuffer.writeln();
}
for (int p = 0; p < vPadding; p++) {
qrBuffer.writeln(whiteWhite * (qrImage.moduleCount + hPadding * 2));
}
return qrBuffer.toString();
}