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.availabilityChanged.listen((final event) {
    final value = event.value.toDart;
    _availabilityStream?.add(value);
  });
  unawaited(getAvailability());
  return _availabilityStream!.stream;
}