connect method
Future
connect(
{ - Duration? timeout = const Duration(seconds: 5),
})
override
Implementation
@override
Future connect({Duration? timeout = const Duration(seconds: 5)}) async {
if (Platform.isWindows) {
if (_hPrinter != null) return;
try {
_hPrinter = _openWindowsPrinter();
} catch (e) {
_hPrinter = null;
return Future.error(e.toString());
}
} else if (Platform.isAndroid) {
if (_androidConnected) return;
final vendorId = printer.vendorId;
final productId = printer.productId;
if (vendorId == null || productId == null) {
return Future.error('USB printer has no vendorId/productId');
}
bool? ok;
try {
ok = await usbPrinter.connect(vendorId, productId);
} catch (e) {
return Future.error('Failed to connect USB printer: $e');
}
if (ok != true) {
return Future.error(
'Failed to connect USB printer ($vendorId:$productId)');
}
_androidConnected = true;
}
}