getPariedBluetoohts static method
Implementation
static Future<List<BluetoothInfo>> getPariedBluetoohts() async {
await initialize();
if (_scanning) return [];
_bluetooths = [];
WinBle.startScanning();
if (_scanStream != null) _scanStream!.cancel();
_scanStream = WinBle.scanStream.listen((BleDevice event) {
//print("device name: ${event.name}");
// Get Devices Here
bool add = true;
for (BluetoothInfo bleDevice in _bluetooths) {
//si el bluetooth address y name es igual no agregar, ya esta agregado
if (bleDevice.macAdress == event.address) {
add = false;
break;
}
}
//add bluetooth in list
//print("event: ${event.name} add: $add isNotEmpty: ${event.name.trim().isNotEmpty}");
if (add && event.name.trim().isNotEmpty) {
_bluetooths.add(BluetoothInfo(name: event.name, macAdress: event.address));
}
});
//Await five seconds for scanning devices
await Future.delayed(const Duration(seconds: 5));
WinBle.stopScanning();
_scanStream?.cancel();
_scanning = false;
return _bluetooths;
}