如何使用 Flutter 在此 POS 上进行打印

发布于 2025-01-09 20:57:18 字数 640 浏览 1 评论 0原文

输入图片此处描述

我尝试了此功能,但不起作用

Future<void> _connect(BluetoothDevice device) async {
  if (device == null) {
    show('No device selected.');
  } else {
    bluetooth.isConnected.then((isConnected) {
      if (!isConnected!) {
        bluetooth.printCustom("thermal pinter", 0, 1);
        for (int i = 0; i < 2; i++) {
          bluetooth.printCustom("Welcome", 0, 1);
          bluetooth.printNewLine();
        }
      }
    });
  }
}

enter image description here

I try this function but doesn't work

Future<void> _connect(BluetoothDevice device) async {
  if (device == null) {
    show('No device selected.');
  } else {
    bluetooth.isConnected.then((isConnected) {
      if (!isConnected!) {
        bluetooth.printCustom("thermal pinter", 0, 1);
        for (int i = 0; i < 2; i++) {
          bluetooth.printCustom("Welcome", 0, 1);
          bluetooth.printNewLine();
        }
      }
    });
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪了杯 2025-01-16 20:57:19

您好,欢迎来到SO!
我对蓝牙打印不太了解,或者您使用的方法是否存在并且使用是否正确,但至少我可以注意到您的代码在未连接打印机时发送打印命令。
请参阅此处:

if (!isConnected!) {
  //the code below is executed only if isConnected is false, but seems like you want it to be the opposite
  bluetooth.printCustom("thermal pinter", 0, 1);
  for (int i = 0; i < 2; i++) {
    bluetooth.printCustom("Welcome", 0, 1);
    bluetooth.printNewLine();
  }
}

假设代码是正确的,则仅当打印机未连接时,if (!isConnected!) 行才会执行后面的 {} 中的代码连接。尝试删除 isConnected 之前的 ! 并查看是否有效。再说一遍,这只是根据您的变量名称等进行的疯狂猜测,我不能真正说问题就在那里。

Hello and welcome on SO!
I don't know much about bluetooth printing or if the methods you're using exists and are used correctly, but at least I can notice that your code is sending the order to print when the printer is NOT connected.
See here:

if (!isConnected!) {
  //the code below is executed only if isConnected is false, but seems like you want it to be the opposite
  bluetooth.printCustom("thermal pinter", 0, 1);
  for (int i = 0; i < 2; i++) {
    bluetooth.printCustom("Welcome", 0, 1);
    bluetooth.printNewLine();
  }
}

Taking for granted that the code is correct, the line if (!isConnected!) will perform the code in the {} that follows only when the printer is not connected. Try removing the ! before isConnected and see if it works. Again, this is simply a wild guess judging on your variables name and such, I can't really say that the problem lies there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文