scanBluetoothPrinters static method

Future<List<PrinterDevice>> scanBluetoothPrinters()

Scan for available Bluetooth printers.

Searches for paired Bluetooth devices that might be Bixolon printers. Requires appropriate Bluetooth permissions to be granted.

Returns a list of discovered Bluetooth printer devices.

Implementation

static Future<List<PrinterDevice>> scanBluetoothPrinters() async {
  try {
    final List<dynamic>? result =
        await _channel.invokeMethod<List<dynamic>>('scanBluetoothDevices');
    if (result == null) {
      return [];
    }

    return result
        .map((device) => PrinterDevice(
              name: device['name'] ?? 'Unknown Device',
              address: device['address'] ?? '',
              connectionType: ConnectionType.bluetooth,
            ))
        .toList();
  } catch (e) {
    print('Error scanning for Bluetooth printers: $e');
    return [];
  }
}