最近在使用flutter开发移动端App的时候,遇到了通过ip直接调用网络打印机,打印机没有反应的问题
点击打印按钮,开始连接打印机
ElevatedButton(
child: const Text("打印"),
onPressed: () async {
const PaperSize paper = PaperSize.mm80;
final profile = await CapabilityProfile.load();
final printer = NetworkPrinter(paper, profile);
final PosPrintResult res = await printer.connect('10.228.109.100', port: 3911);
/// 此处已经success
if (res == PosPrintResult.success) {
testReceipt(printer);
printer.disconnect();
}
print('Print result: ${res.msg}');
},
)
连接成功之后,调用testReceipt方法开始绘制打印
void testReceipt(NetworkPrinter printer) {
print('开始打印');
printer.text(
'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
printer.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
styles: PosStyles(codeTable: 'CP1252'));
printer.text('Special 2: blåbærgrød',
styles: PosStyles(codeTable: 'CP1252'));
printer.text('Bold text', styles: PosStyles(bold: true));
printer.text('Reverse text', styles: PosStyles(reverse: true));
printer.text('Underlined text',
styles: PosStyles(underline: true), linesAfter: 1);
printer.text('Align left', styles: PosStyles(align: PosAlign.left));
printer.text('Align center', styles: PosStyles(align: PosAlign.center));
printer.text('Align right',
styles: PosStyles(align: PosAlign.right), linesAfter: 1);
printer.text('Text size 200%',
styles: PosStyles(
height: PosTextSize.size2,
width: PosTextSize.size2,
));
printer.feed(2);
printer.cut();
print('打印结束');
}
运行结果未报错,控制台输出没有任何问题
代码上没看出任何问题,但是打印机毫无反应
求指点迷津,我错哪了,该怎么做