【问题标题】:Flutter Reactive-BLE infinite duplicate devices found发现 Flutter Reactive-BLE 无限重复设备
【发布时间】:2022-11-10 10:17:06
【问题描述】:

我一直在使用颤振反应,我有以下问题。当我使用函数 scanForDevices 时,它会显示找到的设备无限次重复。我习惯于使用找到的设备只出现一次的库,但这种实现似乎会在设备发出广告时通知您。我该怎么做才能只获取设备的一个实例?我唯一的解决方案是制作地图并将设备 ID 添加为密钥吗?

【问题讨论】:

  • 拥有已检测到设备的地图听起来是个好主意!
  • 您多次检测到哪种设备?

标签: flutter bluetooth bluetooth-lowenergy


【解决方案1】:

尝试使用List类的.every()方法

例子:

_foundBleUARTDevices = [];
_scanning = true;
refreshScreen();
_scanStream =
  flutterReactiveBle.scanForDevices(withServices: []).listen((device) {
    if (_foundBleUARTDevices.every((element) => element.id != device.id)) {
      _foundBleUARTDevices.add(device);
      refreshScreen();
    }
  }, onError: (Object error) {
       _logTexts =
       "${_logTexts}ERROR while scanning:$error 
";
       refreshScreen();
     }
  );
}

for more details

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 2023-01-05
    相关资源
    最近更新 更多