drawQRCode method

  1. @override
dynamic drawQRCode(
  1. String context,
  2. PrinterOffset offset,
  3. PrinterSize size,
  4. 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 > 10) {
    zoom = 10;
  }

  int viewOffset = (size.width! - zoom * qrCode.moduleCount) ~/ 2;

  addCommand(
      'QRCODE ${offset.x!.toInt() + viewOffset},${offset.y!.toInt() + viewOffset},${eccToString(ecc)},$zoom,A,0,"$context"');
}