BleManager class abstract

Entry point for library operations, handling allocation and deallocation of underlying native resources and obtaining Peripheral instances.

The class is a singleton, so there's no need to keep the reference to the object in one's code.

Initialising/deinitialising native clients:

BleManager bleManager = BleManager();
await bleManager.createClient(); //ready to go!
//your BLE logic
bleManager.destroyClient(); //remember to release native resources when they're no longer needed

Obtaining Peripheral:

bleManager.startPeripheralScan().listen((scanResult) {
 //Scan one peripheral and stop scanning
 print("Scanned Peripheral ${scanResult.peripheral.name}, RSSI ${scanResult.rssi}");
 bleManager.stopPeripheralScan(); // stops the scan
});

Constructors

BleManager()
factory

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

bluetoothState() Future<BluetoothState>
Returns current state of the Bluetooth adapter.
cancelTransaction(String transactionId) Future<void>
Cancels transaction's return, resulting in BleError with BleError.errorCode set to BleErrorCode.operationCancelled being returned from transaction's Future.
connectedPeripherals(List<String> serviceUUIDs) Future<List<Peripheral>>
Returns a list of Peripheral: on iOS connected and known to system, on Android connected and known to the library.
createClient({String? restoreStateIdentifier, RestoreStateAction? restoreStateAction}) Future<void>
Allocates native resources.
createUnsafePeripheral(String peripheralId, {String? name}) Peripheral
Creates a peripheral which may not exist or be available. Since the peripheralId might be a UUID or a MAC address, depending on the platform, its format is not validated.
destroyClient() Future<void>
Frees native resources.
disableRadio({String transactionId}) Future<void>
Disables Bluetooth on Android; NOOP on iOS.
enableRadio({String transactionId}) Future<void>
Enables Bluetooth on Android; NOOP on iOS.
isClientCreated() Future<bool>
Checks whether the native client exists.
knownPeripherals(List<String> peripheralIdentifiers) Future<List<Peripheral>>
Returns a list of Peripheral: on iOS known to system, on Android known to the library.
logLevel() Future<LogLevel>
Returns current LogLevel.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
observeBluetoothState({bool emitCurrentValue = true}) Stream<BluetoothState>
Returns a stream of changes to the state of the Bluetooth adapter.
setLogLevel(LogLevel logLevel) Future<void>
Sets specified LogLevel.
startPeripheralScan({int scanMode = ScanMode.lowPower, int callbackType = CallbackType.allMatches, List<String> uuids = const [], bool allowDuplicates = false}) Stream<ScanResult>
Starts scanning for peripherals.
stopPeripheralScan() Future<void>
Finishes the scan operation on the device.
toString() String
A string representation of this object.
inherited

Operators

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