isConnected method

Future<bool> isConnected(
  1. Printer device
)

Check if a device is connected

Implementation

Future<bool> isConnected(Printer device) async {
  if (device.connectionType == ConnectionType.USB) {
    if (Platform.isWindows) {
      // For Windows USB printers, they're always "connected" if they're available
      return true;
    } else {
      return FlutterThermalPrinterPlatform.instance.isConnected(device);
    }
  } else if (device.connectionType == ConnectionType.BLE) {
    try {
      if (device.address == null) {
        return false;
      }
      return device.isConnected ?? false;
    } catch (e) {
      log('Failed to check connection status: $e');
      return false;
    }
  }
  return false;
}