mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-13 20:32:02 +10:00
select BLE device
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user