stopScan method
Optimized stop scanning with better resource cleanup
Implementation
Future<void> stopScan({bool stopBle = true, bool stopUsb = true}) async {
try {
if (stopBle) {
await _stopBleStateSync();
await _bleSubscription?.cancel();
_bleSubscription = null;
await UniversalBle.stopScan();
}
if (stopUsb) {
_queueScanGeneration++;
await _usbSubscription?.cancel();
_usbSubscription = null;
}
} catch (e) {
log('Failed to stop scanning for devices: $e');
}
}