1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Thermal printer is not printing data in flutter

Discussão em 'Mobile' iniciado por Stack, Novembro 4, 2024 às 12:32.

  1. Stack

    Stack Membro Participativo

    I am developing an application using flutter which can print a payment receipt. But i have bought a chinese 'portable mini printer'. model no 'X5'. This printer is not responsing to print data. connection is stable. after calling print method result returning true but still paper role ins not moving. This printer provide an application 'TinyPrint' in the playstore.using the app it is working good. and i can not find any sdk for this printer. what can i do right now?

    Future<void> printTicket() async {
    String? isConnected = await BluetoothThermalPrinter.connectionStatus;
    if (isConnected == "true") {
    List<int> bytes = await getTicket();
    // List<int> bytes = utf8.encode("Hello, Printer!\n\n\n");
    print(bytes);
    // final result = await BluetoothThermalPrinter.writeBytes(bytes);
    final result = await BluetoothThermalPrinter.writeText("hello there");
    print("Print $result");
    } else {
    //Hadnle Not Connected Senario
    }
    }

    Future<List<int>> getTicket() async {
    List<int> bytes = [];
    CapabilityProfile profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm58, profile);

    bytes += generator.text("Demo Shop",
    styles: PosStyles(
    align: PosAlign.center,
    height: PosTextSize.size2,
    width: PosTextSize.size2,
    ),
    linesAfter: 1);

    bytes += generator.text(
    "18th Main Road, 2nd Phase, J. P. Nagar, Bengaluru, Karnataka 560078",
    styles: PosStyles(align: PosAlign.center));
    bytes += generator.text('Tel: +919591708470',
    styles: PosStyles(align: PosAlign.center));

    bytes += generator.hr();
    bytes += generator.row([
    PosColumn(
    text: 'No',
    width: 1,
    styles: PosStyles(align: PosAlign.left, bold: true)),
    PosColumn(
    text: 'Item',
    width: 5,
    styles: PosStyles(align: PosAlign.left, bold: true)),
    PosColumn(
    text: 'Price',
    width: 2,
    styles: PosStyles(align: PosAlign.center, bold: true)),
    PosColumn(
    text: 'Qty',
    width: 2,
    styles: PosStyles(align: PosAlign.center, bold: true)),
    PosColumn(
    text: 'Total',
    width: 2,
    styles: PosStyles(align: PosAlign.right, bold: true)),
    ]);

    bytes += generator.row([
    PosColumn(text: "1", width: 1),
    PosColumn(
    text: "Tea",
    width: 5,
    styles: PosStyles(
    align: PosAlign.left,
    )),
    PosColumn(
    text: "10",
    width: 2,
    styles: PosStyles(
    align: PosAlign.center,
    )),
    PosColumn(text: "1", width: 2, styles: PosStyles(align: PosAlign.center)),
    PosColumn(text: "10", width: 2, styles: PosStyles(align: PosAlign.right)),
    ]);

    bytes += generator.row([
    PosColumn(text: "2", width: 1),
    PosColumn(
    text: "Sada Dosa",
    width: 5,
    styles: PosStyles(
    align: PosAlign.left,
    )),
    PosColumn(
    text: "30",
    width: 2,
    styles: PosStyles(
    align: PosAlign.center,
    )),
    PosColumn(text: "1", width: 2, styles: PosStyles(align: PosAlign.center)),
    PosColumn(text: "30", width: 2, styles: PosStyles(align: PosAlign.right)),
    ]);

    bytes += generator.row([
    PosColumn(text: "3", width: 1),
    PosColumn(
    text: "Masala Dosa",
    width: 5,
    styles: PosStyles(
    align: PosAlign.left,
    )),
    PosColumn(
    text: "50",
    width: 2,
    styles: PosStyles(
    align: PosAlign.center,
    )),
    PosColumn(text: "1", width: 2, styles: PosStyles(align: PosAlign.center)),
    PosColumn(text: "50", width: 2, styles: PosStyles(align: PosAlign.right)),
    ]);

    bytes += generator.row([
    PosColumn(text: "4", width: 1),
    PosColumn(
    text: "Rova Dosa",
    width: 5,
    styles: PosStyles(
    align: PosAlign.left,
    )),
    PosColumn(
    text: "70",
    width: 2,
    styles: PosStyles(
    align: PosAlign.center,
    )),
    PosColumn(text: "1", width: 2, styles: PosStyles(align: PosAlign.center)),
    PosColumn(text: "70", width: 2, styles: PosStyles(align: PosAlign.right)),
    ]);

    bytes += generator.hr();

    bytes += generator.row([
    PosColumn(
    text: 'TOTAL',
    width: 6,
    styles: PosStyles(
    align: PosAlign.left,
    height: PosTextSize.size4,
    width: PosTextSize.size4,
    )),
    PosColumn(
    text: "160",
    width: 6,
    styles: PosStyles(
    align: PosAlign.right,
    height: PosTextSize.size4,
    width: PosTextSize.size4,
    )),
    ]);

    bytes += generator.hr(ch: '=', linesAfter: 1);

    // ticket.feed(2);
    bytes += generator.text('Thank you!',
    styles: PosStyles(align: PosAlign.center, bold: true));

    bytes += generator.text("26-11-2020 15:22:45",
    styles: PosStyles(align: PosAlign.center), linesAfter: 1);

    bytes += generator.text(
    'Note: Goods once sold will not be taken back or exchanged.',
    styles: PosStyles(align: PosAlign.center, bold: false));
    bytes += generator.cut();
    return bytes;
    }


    i have used packages :

    esc_pos_utils: ^1.1.0
    esc_pos_bluetooth: ^0.4.1
    flutter_bluetooth_basic: ^0.1.5
    bluetooth_thermal_printer: ^0.0.6

    Continue reading...

Compartilhe esta Página