adapterStateChanges method

  1. @override
Stream<BluetoothAdapterState> adapterStateChanges()
override

Adapter-state stream. Always emits the current state on listen. Live transition events are emitted by the Linux (BlueZ) backend; macOS, iOS, Android and Windows currently emit the current state once (continuous change events on those platforms are a future enhancement). Use adapterState for a one-shot snapshot.

Implementation

@override
Stream<BluetoothAdapterState> adapterStateChanges() {
  late StreamController<BluetoothAdapterState> proxy;
  StreamSubscription<BluetoothAdapterState>? sub;
  proxy = StreamController<BluetoothAdapterState>.broadcast(
    onListen: () {
      proxy.add(_adapterState);
      sub = _adapterController.stream.listen(proxy.add);
    },
    onCancel: () async => sub?.cancel(),
  );
  return proxy.stream;
}