startScan method
Future<void>
startScan({
- List<
String> serviceUuids = const <String>[], - Duration? timeout,
- bool allowDuplicates = false,
- BluetoothScanMode scanMode = BluetoothScanMode.ble,
开始扫描附近设备。
参数:
serviceUuids:BLE 服务 UUID 过滤列表,默认const <String>[]表示不过滤。 iOS/macOS 上推荐传入目标服务 UUID 以提高可发现性;Android 可为空扫描全部;Web 会作为设备选择器 filters/optionalServices,后续需要访问 GATT 服务时应传入目标 UUID。timeout:扫描超时,默认null表示不自动停止。推荐前台扫描使用Duration(seconds: 10)到Duration(seconds: 15),避免耗电。allowDuplicates:是否允许同一设备重复上报,默认false。需要实时 RSSI 或广播数据变化时可设为true,但会明显增加事件量。scanMode:扫描模式,默认 BluetoothScanMode.ble。Android 支持ble、classic、dual;iOS/macOS 只支持 BLE,会忽略 Classic 相关模式; Linux 使用 BlueZTransport过滤,支持le/bredr/auto发现但 GATT API 仍仅面向 BLE; Windows 当前使用 BLE 广播扫描,classic会返回不支持,dual仅使用 BLE 部分; Web 只支持 BLE 设备选择器,classic会抛不支持,dual仅使用 BLE 部分。
Web 差异:不会持续被动扫描,会打开浏览器设备选择器;用户选中后 scanResults
产生一条结果,RSSI 固定为 0,且 timeout/allowDuplicates 无法控制选择器。
Implementation
Future<void> startScan({
List<String> serviceUuids = const <String>[],
Duration? timeout,
bool allowDuplicates = false,
BluetoothScanMode scanMode = BluetoothScanMode.ble,
}) {
throw UnimplementedError('startScan() has not been implemented.');
}