【问题标题】:Print QR code using esc_pos_printer flutter使用 esc_pos_printer flutter 打印二维码
【发布时间】:2022-06-10 22:37:59
【问题描述】:

我正在使用esc_pos_printer 包,它可以通过网络打印收据。我需要两个功能

  1. 在图库中保存二维码/条形码
  2. 使用热敏打印机/普通打印机打印所述二维码/条形码

为了保存我所做的二维码:

  static Future<File> _saveBarCode(GlobalKey key, String productId) async {
    print("save bar code");
    RenderRepaintBoundary boundary =
        key.currentContext!.findRenderObject() as RenderRepaintBoundary;
    ui.Image image = await boundary.toImage();
    ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    Uint8List pngBytes = byteData!.buffer.asUint8List();
    final tempPath = (await getTemporaryDirectory()).path;
    final path = tempPath + "/" + productId + ".png";
    File imgFile = File(path);
    print(imgFile.path);
    return imgFile.writeAsBytes(pngBytes);
  }

  static void save(GlobalKey key, String productId) async {
    _saveBarCode(key, productId).then((value) async {
      bool? saved = await GallerySaver.saveImage(value.path);
      print("saved: $saved");
    }).catchError((error) {
      print(error);
    });
  }

但是打印部分给我带来了麻烦:

  void printOverNetwork(GlobalKey key, String productId) async {
    const PaperSize paperSize = PaperSize.mm80;
    final profile = await CapabilityProfile.load();
    final printer = NetworkPrinter(paperSize, profile);

    final PosPrintResult result =
        await printer.connect('192.168.0.123', port: 9100);

    _saveBarCode(key, productId).then((value) {
      if (result == PosPrintResult.success) {
        // print the qr/barcode
      }
    });
  }

我该如何解决这个问题?

【问题讨论】:

    标签: flutter barcode pos


    【解决方案1】:

    我想这会对你有所帮助。

    ESC POS Printer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 2020-04-01
      • 2022-12-28
      • 1970-01-01
      • 2020-11-01
      • 2014-06-27
      • 2022-01-26
      相关资源
      最近更新 更多