On an Android Flutter project I need to print on USB POS printers and for testing I have an Epson TM-T20. Sending raw bytes would be ideal. flutter_usb_write package does not work (write returns false) and its status is a bit concerning (no sound null-safety yet, the homepage is in Croatian and there is no issue tracker).
Are there any other options?
Future<void> printOnPOS(String text) async {
// text = String.fromCharCodes([27, 64]) + text; // Initialize printer
text += "\r\n";
try {
var flutterUsbWrite = FlutterUsbWrite();
List<UsbDevice> devices = await flutterUsbWrite.listDevices();
print("devices: $devices");
var device = devices[1]; // this picks the printer, checked correct
var port = await flutterUsbWrite.open(
vendorId: device.vid,
productId: device.pid,
);
print("port: $port");
var rw = await flutterUsbWrite.write(Uint8List.fromList(text.codeUnits));
print("rw: $rw");
await flutterUsbWrite.close();
} on PlatformException catch (e) {
print(e.message);
}
}
Output:
I/flutter ( 7763): devices: [UsbDevice: e0f-3 VMware Virtual USB Mouse, VMware null, UsbDevice: 4b8-e03 TM-T20, EPSON 405551460005550000]
I/flutter ( 7763): port: UsbDevice: 4b8-e03 TM-T20, EPSON 405551460005550000
I/flutter ( 7763): rw: false
D/UsbDeviceConnectionJNI( 7763): close