BLE select cancel

This commit is contained in:
Ben Allfree
2026-02-22 08:05:19 -08:00
parent b4f79c1aae
commit 5522f9a236
2 changed files with 111 additions and 63 deletions
+18 -11
View File
@@ -45,17 +45,22 @@ class _ScannerScreenState extends State<ScannerScreen> {
connector.addListener(_connectionListener);
_bluetoothStateSubscription = FlutterBluePlus.adapterState.listen((state) {
if (mounted) {
setState(() {
_bluetoothState = state;
});
// Cancel scan if Bluetooth turns off while scanning
if (state != BluetoothAdapterState.on) {
unawaited(connector.stopScan());
_bluetoothStateSubscription = FlutterBluePlus.adapterState.listen(
(state) {
if (mounted) {
setState(() {
_bluetoothState = state;
});
// Cancel scan if Bluetooth turns off while scanning
if (state != BluetoothAdapterState.on) {
unawaited(connector.stopScan());
}
}
}
});
},
onError: (Object e) {
debugPrint("Scanner adapterState stream error: $e");
},
);
}
@override
@@ -107,7 +112,9 @@ class _ScannerScreenState extends State<ScannerScreen> {
if (isScanning) {
connector.stopScan();
} else {
connector.startScan();
unawaited(connector.startScan().catchError((e) {
debugPrint("Scanner screen startScan error: $e");
}));
}
},
icon: isScanning