如何使用 Flutter 在此 POS 上进行打印
我尝试了此功能,但不起作用
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();
}
}
});
}
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,欢迎来到SO!
我对蓝牙打印不太了解,或者您使用的方法是否存在并且使用是否正确,但至少我可以注意到您的代码在未连接打印机时发送打印命令。
请参阅此处:
假设代码是正确的,则仅当打印机未连接时,
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:
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!
beforeisConnected
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.