1

I'm using esc_pos_printer package which can print a receipt over network. I need two features

  1. Save a qr/bar code in the gallery
  2. Print said qr/bar code using the thermal printer/regular printer

For saving the qr code I did:

  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);
  }

and

  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);
    });
  }

But the printing part is giving me trouble:

  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
      }
    });
  }

How can I solve the issue?

0 Answers0