getStateStream method

Stream<BluetoothState> getStateStream({
  1. int timer = 1000,
})

Emits the current BluetoothState every time the adapter changes state.

Backed by a BroadcastReceiver listening to BluetoothAdapter.ACTION_STATE_CHANGED on the native side, so the stream only emits when the state actually changes (plus one initial emission on subscription).

The timer parameter is kept for backwards compatibility and is ignored — the stream is event-driven, not polled.

Implementation

Stream<BluetoothState> getStateStream({int timer = 1000}) {
  return _events.receiveBroadcastStream().map((event) {
    return enumFromString(BluetoothState.values, event as String?) ??
        BluetoothState.uknow;
  });
}