UniversalBle class

Constructors

UniversalBle()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

availabilityStream Stream<AvailabilityState>
Bluetooth availability state stream
no setter
onAvailabilityChange OnAvailabilityChange?
Get Bluetooth state availability.
no getter
onConnectionChange OnConnectionChange?
Get connection state changes.
no getter
onPairingStateChange OnPairingStateChange
Get pair state changes.
no getter
onQueueUpdate OnQueueUpdate?
Get updates of remaining items of a queue.
no getter
onScanResult OnScanResult?
Get scan results.
no getter
onValueChange OnValueChange?
Get characteristic value updates, after calling subscribeNotifications or subscribeIndications
no getter
queueType QueueType
Set how commands will be executed. By default, all commands are executed in a global queue (QueueType.global), with each command waiting for the previous one to finish.
no getter
scanStream Stream<BleDevice>
Scan Stream
no setter
timeout Duration?
Set global timeout for all commands. Default timeout is 10 seconds. Set to null to disable.
no getter

Static Methods

characteristicValueStream(String deviceId, String characteristicId) Stream<Uint8List>
Characteristic value stream
clearQueue([String? id]) → void
Clear a queue. Use BleCommandQueue.globalQueueId to clear the global queue. To clear the queue of a specific device, use deviceId as id. If no id is provided, all queues will be cleared.
connect(String deviceId, {Duration? timeout}) Future<void>
Connect to a device. It is advised to stop scanning before connecting. It throws error if device connection fails. Default connection timeout is 60 sec. Can throw ConnectionException or PlatformException.
connectionStream(String deviceId) Stream<bool>
Connection stream of a device
disableBluetooth({Duration? timeout}) Future<bool>
Disable Bluetooth. It might throw errors if Bluetooth is not available. Not supported on Web and Apple.
disconnect(String deviceId, {Duration? timeout}) Future<void>
Disconnect from a device. Get notified of connection state changes in onConnectionChange listener.
discoverServices(String deviceId, {Duration? timeout}) Future<List<BleService>>
Discover services of a device.
enableBluetooth({Duration? timeout}) Future<bool>
Enable Bluetooth. It might throw errors if Bluetooth is not available. Not supported on Web and Apple.
getBluetoothAvailabilityState() Future<AvailabilityState>
Get Bluetooth availability state. To be notified of updates, set onAvailabilityChange listener.
getConnectionState(String deviceId, {Duration? timeout}) Future<BleConnectionState>
Returns connection state of the device. All platforms will return Connected/Disconnected states. Android and Apple can also return Connecting/Disconnecting states.
getSystemDevices({List<String>? withServices, Duration? timeout}) Future<List<BleDevice>>
Get connected devices to the system (connected by any app). Use withServices to filter devices by services. On Apple, withServices is required to get any connected devices. If not passed, several 18XX generic services will be set by default. On Android, Linux and Windows, if withServices is used, then internally all services will be discovered for each device first (either by connecting or by using cached services). Not supported on Web.
isPaired(String deviceId, {BleCommand? pairingCommand, Duration? timeout}) Future<bool?>
Check if a device is paired.
pair(String deviceId, {BleCommand? pairingCommand, Duration? timeout}) Future<void>
Pair a device.
pairingStateStream(String deviceId) Stream<bool>
Pairing state stream
read(String deviceId, String service, String characteristic, {Duration? timeout}) Future<Uint8List>
Read a characteristic value. On iOS and MacOS this command will also trigger onValueChange listener.
readValue(String deviceId, String service, String characteristic, {Duration? timeout}) Future<Uint8List>
receivesAdvertisements(String deviceId) bool
receivesAdvertisements returns true on web if the browser supports receiving advertisements from a certain deviceId. The rest of the platforms will always return true. If true, then you will be getting scanResult updates for this device.
requestMtu(String deviceId, int expectedMtu, {Duration? timeout}) Future<int>
Request MTU value. It will attempt to set the MTU (Maximum Transmission Unit) but it is not guaranteed to succeed due to platform limitations. It will always return the current MTU.
setInstance(UniversalBlePlatform instance) → void
Set custom platform specific implementation (e.g. for testing).
setNotifiable(String deviceId, String service, String characteristic, BleInputProperty bleInputProperty) Future<void>
startScan({ScanFilter? scanFilter, PlatformConfig? platformConfig}) Future<void>
Start scan. Scan results will arrive in onScanResult listener. It might throw errors if Bluetooth is not available. webRequestOptions is supported on Web only.
stopScan() Future<void>
Stop scan. Set onScanResult listener to null if you don't need it anymore. It might throw errors if Bluetooth is not available.
subscribeIndications(String deviceId, String service, String characteristic, {Duration? timeout}) Future<void>
Set a characteristic notifiable. Updates will arrive in onValueChange listener and characteristicValueStream call unsubscribe to stop updates
subscribeNotifications(String deviceId, String service, String characteristic, {Duration? timeout}) Future<void>
Set a characteristic notifiable. Updates will arrive in onValueChange listener and characteristicValueStream call unsubscribe to stop updates
unpair(String deviceId, {Duration? timeout}) Future<void>
Unpair a device. It might throw an error if device is not paired.
unsubscribe(String deviceId, String service, String characteristic, {Duration? timeout}) Future<void>
Stop characteristic notifications/indication updates
write(String deviceId, String service, String characteristic, Uint8List value, {bool withoutResponse = false, Duration? timeout}) Future<void>
Write a characteristic value. To write a characteristic value without response, set withoutResponse to true.
writeValue(String deviceId, String service, String characteristic, Uint8List value, BleOutputProperty bleOutputProperty) Future<void>