connect method

  1. @override
Future<bool> connect({
  1. required Printer printer,
})
override

Implementation

@override
Future<bool> connect({required Printer printer}) async {
  if (printer.type == PrinterType.bluethoot) {
    if (isWindows) {
      return await WinBleManager.instance.connect(printer.bleAddress);
    } else if (isAndroid || isIOS || isMacOS) {
      return await MobileBleManager.instance.connect(printer);
    } else {
      _logPlatformNotSuported();
      return false;
    }
  } else if (printer.type == PrinterType.network) {
    try {
      final networkPrinter = NetworkPrinter(
        host: printer.ip,
        port: int.tryParse(printer.port) ?? 9100,
      );
      return await networkPrinter.connect();
    } catch (e) {
      log('Error connecting network printer: $e', name: 'THERMAL_PRINTER_FLUTTER');
      return false;
    }
  }
  return false;
}