Flutter Print Qr Code Image in Flutter to Thermal Printer

2,495

Have you tried esc_pos_bluetooth for a Bluetooth printer (or esc_pos_printer for a WiFi/network printer)? Both packages can print QR codes

Share:
2,495
Geoffrey Lee
Author by

Geoffrey Lee

Updated on December 10, 2022

Comments

  • Geoffrey Lee
    Geoffrey Lee over 1 year

    I try to print out qr code to thermal printer by using flutter_bluetooth_serial.

    I generate the qr code by using following guide https://medium.com/flutter-community/building-flutter-qr-code-generator-scanner-and-sharing-app-703e73b228d3

    I manage to convert the image into Uint8List and send to the printer.

    Future<Uint8List> _getQrByte() async {
        RenderRepaintBoundary boundary =
            globalKey.currentContext.findRenderObject();
        var image = await boundary.toImage();
        var byteData = await image.toByteData();
        return byteData.buffer.asUint8List();
      }
    

    and I call function in flutter_bluetooth_serial

    await _bluetooth.writeBytes(bytes);
    

    I expect to print a perfect qr code, but the printout is random char and very long.

    In android, I manage to print out by sending byte array from bitmap class to the printer

    • danypata
      danypata about 5 years
      I think you should check a bit how bluetooth works in general. Usually the write operation can handle only 20bytes at a time so you have to chunk your whole byte array in chunks of 20bytes then write them one by one waiting for response from the peripheral. I think you also have to check the docs for printer too.