FakeBluetoothRfcommPlatform class

A scriptable, in-memory BluetoothRfcommPlatform for tests.

Populate bonded, queue discoveryResults to emit, and connect against services. Each openRfcomm returns a FakeRfcommTransport you can drive: push inbound bytes with FakeRfcommTransport.deliver and inspect everything written via FakeRfcommTransport.sent.

Inheritance

Constructors

FakeBluetoothRfcommPlatform({bool supported = true, BluetoothAdapterState adapterState = BluetoothAdapterState.on})

Properties

bonded List<BluetoothDevice>
Bonded devices returned by bondedDevices.
final
connectDelay Duration?
If set, openRfcomm waits this long before returning — lets tests observe the facade's connect-in-flight behavior (scan pausing etc.).
getter/setter pair
connectError Object?
If set, openRfcomm throws this instead of returning a transport.
getter/setter pair
discoveryCompletes bool
Whether a discovery stream closes after emitting discoveryResults, mirroring the real inquiry-completes platforms (Windows/macOS/Android). Set false to model Linux, whose discovery streams stay open.
getter/setter pair
discoveryError Object?
If set, the discovery stream emits this error (after any discoveryResults) so tests can exercise error-surfacing paths.
getter/setter pair
discoveryResults List<BluetoothDiscoveryResult>
Sightings emitted (in order) when startDiscovery is listened to.
final
discoveryStarted bool
getter/setter pair
discoveryStopped bool
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
paired List<DeviceId>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
services Map<DeviceId, List<BluetoothService>>
SDP services returned by discoverServices, keyed by device id.
final
startDiscoveryCount int
Number of platform inquiries actually started/stopped. The booleans above saturate, so they cannot distinguish one inquiry from N — which is exactly the defect the facade's shared-inquiry machinery exists to prevent. Assert on these.
getter/setter pair
stopDiscoveryCount int
getter/setter pair
supported bool
getter/setter pair
transportMaxPayloadSize int?
Seeds FakeRfcommTransport.maxPayloadSize on every transport handed out by openRfcomm. Null (the default) models Windows/Linux/iOS, where the OS advertises no per-write payload limit.
getter/setter pair
transports List<FakeRfcommTransport>
Transports handed out by openRfcomm, in creation order.
final
unpaired List<DeviceId>
final

Methods

adapterState() Future<BluetoothAdapterState>
Current adapter power/authorization state.
override
adapterStateChanges() Stream<BluetoothAdapterState>
Adapter state transitions. Broadcast; emits the current state on listen.
override
bondedDevices() Future<List<BluetoothDevice>>
Paired (bonded) devices known to the OS.
override
discoverServices(DeviceId device, {Uuid? serviceUuid}) Future<List<BluetoothService>>
Resolves the RFCOMM services advertised by device id via SDP, optionally filtered to a single serviceUuid.
override
dispose() Future<void>
Releases any global resources held by the backend.
override
emitAdapterState(BluetoothAdapterState state) → void
isSupported() Future<bool>
Whether this platform can do Bluetooth Classic RFCOMM at all.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openRfcomm(DeviceId device, {int? channel, required Uuid serviceUuid, Duration? timeout}) Future<RfcommTransport>
Opens an RFCOMM channel to device id. If channel is given it is used verbatim; otherwise the channel is resolved from SDP for serviceUuid.
override
pair(DeviceId device) Future<void>
Pairs with device id. Optional capability — may throw BluetoothUnsupportedException.
override
setAdapterEnabled(bool enabled) Future<void>
Requests the radio be powered on/off. Throws BluetoothUnsupportedException where the OS forbids programmatic control.
override
startDiscovery() Stream<BluetoothDiscoveryResult>
Starts a real radio inquiry and streams sightings of nearby devices, paired or not. Cancelling the subscription (or calling stopDiscovery) aborts the inquiry on every backend.
override
stopDiscovery() Future<void>
Stops any in-progress inquiry.
override
toString() String
A string representation of this object.
inherited
unpair(DeviceId device) Future<void>
Removes the bond with device id. Optional capability.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

sampleDevice({String address = 'AA:BB:CC:DD:EE:FF', String name = 'Test Device'}) BluetoothDevice
A ready-made sample device for convenience.