getPairedPrinters method
Gets paired (bonded) Bluetooth devices Uses Android Bluetooth API to get bonded devices
Returns a list of paired Bluetooth devices as BluetoothDevice objects
Implementation
Future<List<BluetoothDevice>> getPairedPrinters() async {
try {
print('[PrinterManager] getPairedPrinters called');
final result = await _channel.invokeMethod('getPairedPrinters');
if (result == null) {
print('[PrinterManager] getPairedPrinters returned null');
return [];
}
final List<dynamic> devicesList = result as List<dynamic>;
print('[PrinterManager] getPairedPrinters found ${devicesList.length} printers');
// Map'i BluetoothDevice'a dönüştür
final devices =
devicesList.map((deviceMap) {
final map = Map<String, dynamic>.from(deviceMap as Map);
return BluetoothDevice(
name: map['friendlyName'] as String?,
address: map['address'] as String,
type: BluetoothDeviceType.classic, // Paired devices are classic Bluetooth
bondState: BluetoothBondState.bonded, // All are bonded
isConnected: false, // Initial state
);
}).toList();
return devices;
} on PlatformException catch (e) {
print('[PrinterManager] getPairedPrinters error: ${e.code} - ${e.message}');
throw Exception("Get Paired Printers Error (${e.code}): ${e.message}");
}
}