select BLE device

This commit is contained in:
Ben Allfree
2026-02-22 08:10:16 -08:00
parent 5522f9a236
commit 6ac987e7cf
+22 -6
View File
@@ -739,13 +739,23 @@ class MeshCoreConnector extends ChangeNotifier {
}, },
); );
await FlutterBluePlus.startScan( if (PlatformInfo.isWeb) {
withServices: [Guid(MeshCoreUuids.service)], await FlutterBluePlus.startScan(
timeout: timeout, withServices: [Guid(MeshCoreUuids.service)],
androidScanMode: AndroidScanMode.lowLatency, );
); // On web, the chooser returns once a device is picked, but the scanResults
// stream might take a moment to emit the last result. Wait briefly so the
// device appears in the UI before stopScan() clears the list.
await Future.delayed(const Duration(milliseconds: 500));
} else {
await FlutterBluePlus.startScan(
withServices: [Guid(MeshCoreUuids.service)],
timeout: timeout,
androidScanMode: AndroidScanMode.lowLatency,
);
await Future.delayed(timeout); await Future.delayed(timeout);
}
} catch (e) { } catch (e) {
debugPrint("Scan error: $e"); debugPrint("Scan error: $e");
// On web, suppress common cancellation and chooser errors // On web, suppress common cancellation and chooser errors
@@ -776,6 +786,12 @@ class MeshCoreConnector extends ChangeNotifier {
} }
} catch (_) {} } catch (_) {}
_scanSubscription = null; _scanSubscription = null;
// On web, don't clear results immediately so the picked device remains visible
if (!PlatformInfo.isWeb) {
_scanResults.clear();
notifyListeners();
}
} }
Future<void> connect(BluetoothDevice device, {String? displayName}) async { Future<void> connect(BluetoothDevice device, {String? displayName}) async {