简体   繁体   English

如何在 Flutter 上实现打印队列?

[英]How to Implement a Print Queue on Flutter?

I´m using esc_pos_bluetooth 0.2.8 library and connect the printer by bluetooth Is ok when I send one order at a time, but when there are simultaneous orders, it print just the first and ignore the others.我正在使用 esc_pos_bluetooth 0.2.8 库并通过蓝牙连接打印机当我一次发送一个订单时可以,但是当有同时订单时,它只打印第一个并忽略其他订单。 I try implement a print queue but I was not successful.我尝试实现打印队列,但没有成功。

List printQueue = [];

insertPrintQueue(Schema item) {
    printQueue.add(item);
    printTicket(printQueue[0]);
  }

  verifyPrintQueue() {
    if (printQueue.length > 0) {
      printTicket(printQueue[0]);
    }
  }

  printTicket(Schema item) async {
      if (printerDevices != null) {
        printerManager.selectPrinter(printerDevices[0]);
        await printerManager
            .printTicket(await ticket.templateTicket(item))
            .then((value) => {
                  printQueue.removeAt(0),
                  if (printQueue.length > 0)
                    {
                      printTicket(printQueue[0])
                    }
                });
      } else {
      print("None Printer Found");
  }

I think this is happening because I'm trying to print while the printer is busy, have a way to check the status of the printer?我认为这是因为我试图在打印机忙碌时打印,有办法检查打印机的状态吗? and just order the print when the printer is not printing并在打印机不打印时订购打印

insertPrintQueue(Schema item) {
  printQueue.add(item);
  printTicket(printQueue[0]); // Here
}

You are trying to print the first item always.您总是试图打印第一项。 So it works as expected.所以它按预期工作。 You can do it like this:你可以这样做:

insertPrintQueue(Schema item) {
  printQueue.add(item);
  //printTicket(printQueue[0]);

  for (var ticket in printQueue) {
      printTicket(ticket);
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM