BluetoothDevice class

Implemented types
Available extensions

Constructors

BluetoothDevice.fromId(String address)
Create a device from an id
factory

Properties

bondState AsyncValueStream<BluetoothBondState>
The bond state of the device (Android Only), as a stream that also exposes the current value via await device.bondState.value.
latefinal
connectionState ValueStream<BluetoothConnectionState>
The connection state of our app to the device, as a stream that also exposes the current value via device.connectionState.value.
latefinal
disconnectReason DisconnectReason?
The most recent disconnection reason
no setter
hashCode int
The hash code for this object.
no setteroverride
isConnected bool
Returns true if this device is currently connected to your app.
no setter
logPath String
The bracketed path identifying this object in logs, outermost first — e.g. a characteristic is [remoteId][service][characteristic].
no setteroverride
maxAttrLen ValueStream<int>
The maximum attribute length in bytes, derived from mtu. Use device.maxAttrLen.value for the current value.
latefinal
mtu ValueStream<int>
The MTU size in bytes, as a stream that also exposes the current value:
latefinal
onServicesReset Stream<void>
Services Reset Stream
no setter
platformName String
platform name
no setter
prevBondState BluetoothBondState?
Get the previous bondState of the device (Android Only)
no setter
remoteId String
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
services List<BluetoothService>
Get services
no setter

Methods

cancelWhenDisconnected(StreamSubscription subscription, {bool next = false, bool delayed = false}) → void
Register a subscription to be canceled when the device is disconnected. This function simplifies cleanup, so you can prevent creating duplicate stream subscriptions.
clearGattCache() Future<void>
Refresh ble services & characteristics (Android Only)
connect({Duration timeout = const Duration(seconds: 35), int? mtu = _mtuMax}) Future<void>
Establishes a connection to the Bluetooth Device. timeout if timeout occurs, cancel the connection request and throw exception mtu Android only. Request a larger mtu right after connection, if set.
createBond({Uint8List? pin, Duration timeout = const Duration(seconds: 90)}) Future<void>
Force the bonding popup to show now (Android Only) Note! calling this is usually not necessary!! The platform does it automatically.
disconnect({Duration timeout = const Duration(seconds: 35), bool queue = true, Duration androidDelay = const Duration(seconds: 2)}) Future<void>
Cancels connection to the Bluetooth Device
discoverServices({bool subscribeToServicesChanged = true, Duration timeout = const Duration(seconds: 15)}) Future<List<BluetoothService>>
Discover services, characteristics, and descriptors of the remote device
ensureConnected(String functionName) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openL2capChannel(int psm, {bool secure = false, Duration timeout = const Duration(seconds: 15)}) Future<BluetoothL2CapChannel>
Open an L2CAP connection-oriented channel to psm — a bidirectional byte stream to the peer, independent of GATT (Android & iOS/macOS only; not supported on Web).
readRssi({Duration timeout = const Duration(seconds: 15)}) Future<int>
Read the RSSI of connected remote device
removeBond({Duration timeout = const Duration(seconds: 30)}) Future<void>
Remove bond (Android Only)
requestConnectionPriority({required ConnectionPriority connectionPriorityRequest, Duration timeout = const Duration(seconds: 3)}) Future<void>
Request connection priority update (Android only)
requestMtu(int desiredMtu, {Duration predelay = const Duration(milliseconds: 350), Duration timeout = const Duration(seconds: 15)}) Future<int>
Request to change MTU (Android Only)
setPreferredPhy({required Set<Phy> txPhy, required Set<Phy> rxPhy, required PhyCoding option, Duration timeout = const Duration(seconds: 3)}) Future<void>
Set the preferred connection (Android Only)
toString() String
A string representation of this object.
override

Operators

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