getPrinters method

  1. @override
Future<List<Printer>> getPrinters({
  1. required PrinterType printerType,
})
override

Implementation

@override
Future<List<Printer>> getPrinters({required PrinterType printerType}) async {
  if (printerType == PrinterType.usb) {
    try {
      final List<dynamic>? printers = await methodChannel.invokeMethod<List<dynamic>>('getPrinters');
      final List<String> resultWin = printers?.cast<String>() ?? [];
      return resultWin.map((p) => Printer(type: PrinterType.usb, name: p)).toList();
    } catch (e) {
      log('Error getting USB printers: $e', name: 'THERMAL_PRINTER_FLUTTER');
      return [];
    }
  } else if (printerType == PrinterType.bluethoot) {
    try {
      if (isWindows) {
        return await WinBleManager.instance.scanPrinters();
      } else if (isAndroid || isIOS || isMacOS) {
        return await MobileBleManager.instance.scanPrinters();
      } else {
        _logPlatformNotSuported();
        return [];
      }
    } catch (e) {
      log('Error getting Bluetooth printers: $e', name: 'THERMAL_PRINTER_FLUTTER');
      return [];
    }
  } else if (printerType == PrinterType.network) {
    // For network printers, the user needs to provide IP and port manually
    return [];
  }

  return [];
}