onAvailabilityChanged static method

Stream<bool> onAvailabilityChanged()

Get a Stream for the availability of a Bluetooth adapter. If a user inserts or removes a bluetooth adapter from their devices this stream will update. It will not necessarily update if the user enables/ disables a bluetooth adapter.

Implementation

static Stream<bool> onAvailabilityChanged() {
  if (!isBluetoothAPISupported()) {
    return Stream.value(false);
  }
  if (_availabilityStream != null) {
    return _availabilityStream!.stream;
  }
  _availabilityStream = WebBehaviorSubject();
  _nativeBluetooth.addEventListener("availabilitychanged",
      _JSUtil.allowInterop((final event) {
    final value = _JSUtil.getProperty(event, "value");
    if (value is bool) {
      _availabilityStream?.add(value);
    }
  }));
  //ignore: discarded_futures
  getAvailability();
  return _availabilityStream!.stream;
}