Developing an app on Flutter that's meant to print stuff out, I am using the 'esc_pos_printer' plugin. Works perfectly fine on other devices (IOS, Android) but doesn't work on windows. The issue is not in the computer or the printer, other apps print just fine.
Here's my print function:
Future<void> print({required Uint8List source, String? printerID, StreamController? controller}) async {
await getPrinterConfig(printerID: printerID, controller: controller);
final details = 'Address: $targetIP $targetPort. Type: ${targetType.name.toUpperCase()}';
try {
switch (targetType) {
case AppPrinterTargetType.lan:
final profile = await CapabilityProfile.load();
final printer = NetworkPrinter(targetPapersize, profile);
controller?.add('Connecting to printer... $details');
final PosPrintResult status =
await printer.connect(targetIP, port: int.parse(targetPort)).timeout(const Duration(seconds: 10));
if (status == PosPrintResult.success) {
controller?.add('Connected! $details');
printer.beep(n: 3, duration: PosBeepDuration.beep250ms);
controller?.add('Printing started! $details');
final Image? image = decodeImage(source);
Image imageResized = copyResize(image!, width: 500); //210
printer.image(imageResized, align: PosAlign.center);
printer.cut(mode: PosCutMode.partial);
controller?.add('Printing process done.');
printer.disconnect();
} else {
controller?.add('Connection timeout. $details');
}
case AppPrinterTargetType.bluetooth:
return controller?.add('Under development.');
case AppPrinterTargetType.epson:
return controller?.add('Under development.');
case AppPrinterTargetType.star:
if (targetIP.isEmpty) {
await starPrintToAllIp(targetIP, source, controller);
} else
if (isValidIpAddress(targetIP)) {
if (await starPrinterGetStatus('TCP:$targetIP')) {
controller?.add('Connected! $details');
await startPrintToIp('TCP:$targetIP', '', source);
controller?.add('Printing process done.');
} else {
controller?.add('Connection timeout. $details');
}
} else
if (isValidMacAddress(targetIP) == true) {
final printerIp = await secureDB.read(key: 'starPrinterIp') ?? '';
if (await starPrinterGetStatus(printerIp)) {
key: starPrinterIp
controller?.add('Connected! $details');
await startPrintToIp(printerIp, '', source);
controller?.add('Printing process done.');
} else {
await starPrintToAllIp(targetIP, source, controller);
}
}
case AppPrinterTargetType.cloudStar:
controller?.add('printing to star cloud');
String source64 = base64Encode(source);
var body = {
"mac": [targetIP],
//"name": "Unique name",
//"header": "some text",
//"footer": "some text",
"logo": "data:image/jpeg;base64,$source64"
};
final token = await secureDB.read(key: 'token');
final responses = await remoteDB.post(
'/addQueueToPrint',
options: Options(headers: {"Authorization": "Bearer $token"}),
data: json.encode(body),
);
final data = responses.data;
return controller?.add(data['result']);
}
} catch (error) {
controller?.add('Error when connecting: $error. $details');
}
await Future.delayed(const Duration(seconds: 5)).then((value) => controller?.add('.'));
}
I tried checking if the plugins and dependencies do not support windows, they all seem to do. Tried printing out on a different printer.