drawQRCode method
dynamic
drawQRCode(
- String context,
- PrinterOffset offset,
- PrinterSize size,
- ECCLevelEnum ecc,
override
打印二维码
context
内容
offset
偏移位置
size
大小
ecc
纠错等级
Implementation
@override
drawQRCode(String context, PrinterOffset offset, PrinterSize size, ECCLevelEnum ecc) {
final qrCode = QrCode.fromData(data: context, errorCorrectLevel: eccToLibNumber(ecc));
int zoom = size.width! ~/ qrCode.moduleCount;
if (zoom == 0) {
throw new Exception("宽度太小");
}
if (zoom > 32) {
zoom = 32;
}
int viewOffset = (size.width! - zoom * qrCode.moduleCount) ~/ 2;
addCommand(
"B QR ${offset.x!.toInt() + viewOffset} ${offset.y!.toInt() + viewOffset} U $zoom");
addCommand("${_eccToStr(ecc)}A,$context");
addCommand("ENDQR");
}