destroy method

void destroy()

销毁设备对象,不然可能会存在重复的设备对象,当

Implementation

void destroy() {
  if (_state != DeviceState.destroyed) {
    _state = DeviceState.destroyed; //将设备状态置为已销毁
    _isWatchingRssi = false;
    _stateStreamController.add(DeviceState.destroyed); //广播状态变化
    FlutterBlueElves.instance._deviceCache.remove(_id); //从cache中移除
    FlutterBlueElves.instance._channel
        .invokeMethod('destroy', {"id": _id}); //销毁底层的设备对象
    _stateStreamController.close(); //关闭流
    _serviceDiscoveryStreamController.close(); //关闭流
    _deviceSignalResultStreamController.close(); //关闭流
    _rssiStreamController.close(); //关闭流
  }
}