getPrinters method

Future<void> getPrinters({
  1. Duration refreshDuration = const Duration(seconds: 2),
  2. List<ConnectionType> connectionTypes = const [ConnectionType.BLE, ConnectionType.USB, ConnectionType.NETWORK],
  3. bool androidUsesFineLocation = false,
})

Discover BLE and USB printers, plus installed network queues on macOS. Network discovery on other platforms still requires an explicit IP address.

Implementation

Future<void> getPrinters({
  Duration refreshDuration = const Duration(seconds: 2),
  List<ConnectionType> connectionTypes = const [
    ConnectionType.BLE,
    ConnectionType.USB,
    ConnectionType.NETWORK,
  ],
  bool androidUsesFineLocation = false,
}) async {
  if (connectionTypes.isEmpty) {
    throw Exception('No connection type provided');
  }
  _scanConnectionTypes = connectionTypes.toSet();
  _queueScanGeneration++;
  await _usbSubscription?.cancel();
  _usbSubscription = null;
  sortDevices();

  if (Platform.isMacOS &&
      (connectionTypes.contains(ConnectionType.USB) ||
          connectionTypes.contains(ConnectionType.NETWORK))) {
    await _getMacOSPrinters(refreshDuration);
  } else if (connectionTypes.contains(ConnectionType.USB)) {
    await _getUSBPrinters(refreshDuration);
  }

  if (connectionTypes.contains(ConnectionType.BLE)) {
    await _getBLEPrinters(androidUsesFineLocation);
  }
}