### Specify Web Optional Services via PlatformConfig for UniversalBle Scan Source: https://pub.dev/documentation/universal_ble/latest/index This Dart example illustrates how to use `PlatformConfig` within `UniversalBle.startScan` to specify `optionalServices` specifically for web platforms. This allows access to certain services after connection without necessarily applying them as a scan filter during the initial scan. ```Dart UniversalBle.startScan( platformConfig: PlatformConfig( web: WebOptions( optionalServices: ["SERVICE_UUID"] ) ) ) ``` -------------------------------- ### Manage Bluetooth Availability State Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble Provides examples for checking the current Bluetooth availability state, listening for state changes, and programmatically enabling or disabling Bluetooth using `UniversalBle`. ```Dart // Get current Bluetooth availability state AvailabilityState availabilityState = UniversalBle.getBluetoothAvailabilityState(); // e.g. poweredOff or poweredOn, // Receive Bluetooth availability changes UniversalBle.onAvailabilityChange = (state) { // Handle the new Bluetooth availability state }; // Enable Bluetooth programmatically UniversalBle.enableBluetooth(); // Disable Bluetooth programmatically UniversalBle.disableBluetooth(); ``` -------------------------------- ### Scan Filter: withNamePrefix Parameter (APIDOC) Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble Defines the `withNamePrefix` parameter for filtering devices by name. Scan results will include devices whose names match or start with any of the provided strings (case-sensitive). ```APIDOC List withNamePrefix; ``` -------------------------------- ### Dart: UniversalBle.startScan Method Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/startScan This asynchronous Dart method provides the internal implementation for initiating a Bluetooth scan. It queues the scan command to the underlying platform, ensuring proper execution flow and handling of optional scan filters and platform configurations. ```Dart static Future startScan({ ScanFilter? scanFilter, PlatformConfig? platformConfig, }) async { return await _bleCommandQueue.queueCommandWithoutTimeout( () => _platform.startScan( scanFilter: scanFilter, platformConfig: platformConfig, ), ); } ``` -------------------------------- ### Get String Representation of BleDevice Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDevice-class Provides a string representation of this object. This method overrides the default toString behavior. ```APIDOC BleDevice.toString() -> String ``` -------------------------------- ### Get Bluetooth Availability State Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Retrieves the current availability state of the Bluetooth adapter. This is useful for checking if Bluetooth is enabled, disabled, or in another state. ```APIDOC UniversalBlePlatform.getBluetoothAvailabilityState() -> Future ``` -------------------------------- ### UniversalBlePlatform.startScan Method Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/startScan The abstract method signature for `startScan` in the `UniversalBlePlatform` class, defining its return type and optional parameters for scan filtering and platform-specific configurations. ```Dart Future startScan({ ScanFilter? scanFilter, PlatformConfig? platformConfig, }); ``` -------------------------------- ### Retrieve a Specific BLE Characteristic from Service Source: https://pub.dev/documentation/universal_ble/latest/index Retrieves a `BleCharacteristic` object using its UUID from an already obtained `BleService` object. This is an alternative to getting it directly from the device. ```Dart BleCharacteristic characteristic = await service.getCharacteristic('2a56'); ``` -------------------------------- ### UniversalBlePlatform.startScan API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/startScan API specification for the `startScan` method, outlining its return type and parameters within the `UniversalBlePlatform` class. ```APIDOC UniversalBlePlatform: startScan: Return Type: Future Parameters: scanFilter: ScanFilter? platformConfig: PlatformConfig? ``` -------------------------------- ### WebOptions Constructor Dart Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/WebOptions/WebOptions The Dart implementation of the WebOptions constructor, showing how the optionalServices and optionalManufacturerData fields are initialized with default empty lists if not provided. ```Dart WebOptions({ this.optionalServices = const [], this.optionalManufacturerData = const [], }); ``` -------------------------------- ### Get BLE Connection State Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Fetches the current connection state of a specified BLE device. It returns a BleConnectionState enum value indicating whether the device is connected, disconnected, or connecting. ```APIDOC UniversalBlePlatform.getConnectionState(String deviceId) -> Future ``` -------------------------------- ### UniversalBle.connect Static Method API Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/connect Documents the signature, parameters, return type, and potential exceptions for the static `connect` method of the `UniversalBle` class, used to establish a connection to a BLE device. ```APIDOC UniversalBle.connect static method: Signature: Future connect(String deviceId, {Duration? connectionTimeout}) Parameters: deviceId: String - The ID of the device to connect to. connectionTimeout: Duration? (optional) - The maximum time to wait for a connection. Defaults to 60 seconds. Returns: Future Description: Connects to a specified Bluetooth Low Energy (BLE) device. Notes: It is advised to stop scanning before connecting. Throws: ConnectionException: If the device connection fails or times out. PlatformException: For platform-specific errors. ``` -------------------------------- ### Get Connection State Stream Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Provides a stream that emits the connection state (connected or disconnected) of a specified BLE device. This stream is ideal for monitoring device connectivity changes dynamically. ```APIDOC UniversalBlePlatform.connectionStream(String deviceId) -> Stream ``` -------------------------------- ### UniversalBle.getSystemDevices Method API Documentation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/getSystemDevices API details for the `getSystemDevices` static method, including its signature, parameters, return type, and platform-specific considerations for filtering devices by services. ```APIDOC UniversalBle.getSystemDevices static method Return Type: Future> Signature: getSystemDevices({ List? withServices, }) Parameters: withServices: List? Description: Use to filter devices by services. Platform Specifics: Apple: Required to get any connected devices. If not passed, several 18XX generic services will be set by default. Android, Linux, Windows: If used, then internally all services will be discovered for each device first (either by connecting or by using cached services). Description: Get connected devices to the system (connected by any app). Limitations: Not supported on Web. ``` -------------------------------- ### Get Characteristic Value Stream Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Retrieves a stream of characteristic values for a specified BLE device and characteristic. This method is useful for receiving real-time data updates from a connected BLE peripheral. ```APIDOC UniversalBlePlatform.characteristicValueStream(String deviceId, String characteristicId) -> Stream ``` -------------------------------- ### Dart Implementation of UniversalBle.getSystemDevices Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/getSystemDevices The Dart implementation of the `getSystemDevices` static method, showing how it queues a command to the platform-specific implementation to retrieve system devices. ```Dart static Future> getSystemDevices({ List? withServices, }) async { return await _bleCommandQueue.queueCommand( () => _platform.getSystemDevices(withServices?.toValidUUIDList()), ); } ``` -------------------------------- ### Get scanStream Property Implementation in Dart Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/scanStream This code snippet illustrates the implementation of the `scanStream` getter. It directly exposes the stream from an internal `_scanStreamController`, allowing consumers to listen for `BleDevice` updates. ```Dart Stream get scanStream => _scanStreamController.stream; ``` -------------------------------- ### BleCapabilities Default Constructor Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleCapabilities/BleCapabilities Initializes a new instance of the BleCapabilities class. This constructor takes no parameters and creates a default BleCapabilities object. ```APIDOC BleCapabilities() ``` -------------------------------- ### APIDOC: UniversalBle.startScan Method Signature Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/startScan Defines the API signature for the `startScan` static method of the `UniversalBle` class. It returns a `Future` and accepts optional `ScanFilter` and `PlatformConfig` parameters for controlling the scan behavior. ```APIDOC UniversalBle.startScan: Method: static Future startScan({ScanFilter? scanFilter, PlatformConfig? platformConfig}) Return Type: Future Description: Initiates a Bluetooth scan. Scan results are delivered to the onScanResult listener. May throw errors if Bluetooth is unavailable. webRequestOptions is Web-only. Parameters: scanFilter: Type: ScanFilter? Description: An optional filter to apply to the scan results. platformConfig: Type: PlatformConfig? Description: Optional platform-specific configuration for the scan. ``` -------------------------------- ### Get BLE Pairing State Stream Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle-class Provides a stream that emits the pairing state of a specified Bluetooth Low Energy device. Useful for observing real-time pairing status changes. ```APIDOC pairingStateStream(String deviceId) → Stream ``` -------------------------------- ### Get Detailed BLE Device Connection State (Dart) Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble Fetches the detailed connection state of a BLE device, which can be `connected`, `disconnected`, `connecting`, or `disconnecting`, providing more granular status information. ```Dart BleConnectionState connectionState = await bleDevice.connectionState; ``` -------------------------------- ### UniversalBle.discoverServices Static Method API Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/discoverServices API documentation for the `discoverServices` static method of the `UniversalBle` class. This method asynchronously discovers and returns a list of Bluetooth services for a given device ID. ```APIDOC UniversalBle: discoverServices(deviceId: String): Future> deviceId: The unique identifier of the Bluetooth device. ``` -------------------------------- ### Dart Implementation of UniversalBle.discoverServices Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/discoverServices The Dart implementation of the `discoverServices` static method. It uses an internal command queue to call the platform-specific service discovery, ensuring proper execution flow and handling for the specified device. ```Dart static Future> discoverServices(String deviceId) async { return await _bleCommandQueue.queueCommand( () => _platform.discoverServices(deviceId), deviceId: deviceId, ); } ``` -------------------------------- ### Listen for BLE Characteristic Value Changes Source: https://pub.dev/documentation/universal_ble/latest/index Subscribes to the `onValueReceived` stream of a `BleCharacteristic` to get real-time updates whenever its value changes. The stream emits `Uint8List` values. ```Dart characteristic.onValueReceived.listen((value) { debugPrint('Received value: ${value.toString()}'); }); ``` -------------------------------- ### BleService Class API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleService-class Comprehensive API documentation for the `BleService` class, detailing its initialization, accessible properties, and available methods for interacting with Bluetooth Low Energy characteristics. This includes inherited members from `Object` and methods provided by extensions. ```APIDOC BleService class: Available extensions: - BleServiceExtension Constructors: BleService.new(String uuid, List characteristics) Properties: characteristics: List (getter/setter pair) hashCode: int (The hash code for this object. inherited) runtimeType: Type (A representation of the runtime type of the object. inherited) uuid: String (getter/setter pair) Methods: getCharacteristic(String characteristicId): BleCharacteristic Description: Retrieves a BleCharacteristic from the service by its UUID. Source: Available on BleService, provided by the BleServiceExtension extension noSuchMethod(Invocation invocation): dynamic (Invoked when a nonexistent method or property is accessed. inherited) toString(): String (A string representation of this object. override) Operators: operator ==(Object other): bool (The equality operator. inherited) ``` -------------------------------- ### Get Pairing State Stream Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Provides a stream that emits the pairing state (paired or unpaired) of a specified BLE device. This stream is useful for monitoring changes in the device's pairing status. ```APIDOC UniversalBlePlatform.pairingStateStream(String deviceId) -> Stream ``` -------------------------------- ### UniversalBlePlatform.discoverServices Method API Documentation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/discoverServices API documentation for the `discoverServices` abstract method, detailing its return type and parameters. This method is part of the `UniversalBlePlatform` class and is used to discover Bluetooth Low Energy services for a specified device. ```APIDOC UniversalBlePlatform.discoverServices: Signature: Future> discoverServices(String deviceId) Parameters: deviceId: Type: String Description: The ID of the device for which to discover services. Returns: Type: Future> Description: A Future that completes with a list of discovered BleService objects. ``` -------------------------------- ### Check and Listen for Bluetooth Availability (Dart) Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble Shows how to check the current Bluetooth availability state and how to listen for changes in availability using a stream or a handler, ensuring scans only start when Bluetooth is powered on. ```Dart AvailabilityState state = await UniversalBle.getBluetoothAvailabilityState(); // Start scan only if Bluetooth is powered on if (state == AvailabilityState.poweredOn) { UniversalBle.startScan(); } // Listen to bluetooth availability changes using stream UniversalBle.availabilityStream.listen((state) { if (state == AvailabilityState.poweredOn) { UniversalBle.startScan(); } }); // Or set a handler UniversalBle.onAvailabilityChange = (state) {}; ``` -------------------------------- ### Get System Paired BLE Devices Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Retrieves a list of BLE devices that are known to the system, optionally filtered by a list of service UUIDs. This method is useful for finding previously paired or system-registered devices. ```APIDOC UniversalBlePlatform.getSystemDevices(List? withServices) -> Future> ``` -------------------------------- ### BleCommand Class API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleCommand-class Comprehensive API documentation for the `BleCommand` class, including its constructor for initialization, properties for accessing service, characteristic, and write values, and inherited methods/operators. This class is fundamental for structuring BLE commands within the `universal_ble` framework. ```APIDOC BleCommand class: Constructors: BleCommand.new({required String service, required String characteristic, Uint8List? writeValue}) Properties: characteristic: String (getter/setter pair) hashCode: int (The hash code for this object. no setter, inherited) runtimeType: Type (A representation of the runtime type of the object. no setter, inherited) service: String (getter/setter pair) writeValue: Uint8List? (getter/setter pair) 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) ``` -------------------------------- ### UniversalBle.pair Method Signature (APIDOC) Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/pair API documentation for the `pair` static method of the `UniversalBle` class. It details the method's parameters, return type, and general behavior, including platform-specific considerations and potential exceptions. ```APIDOC UniversalBle.pair static method: Signature: Future pair(String deviceId, {BleCommand? pairingCommand, Duration? connectionTimeout}) Parameters: deviceId: String - The ID of the device to pair. pairingCommand: BleCommand? (optional) - A command to execute during pairing, especially for devices with encrypted characteristics. It is advised to pass a pairingCommand with an encrypted read or write characteristic. If not passed, use isPaired with a pairingCommand to verify pairing state. connectionTimeout: Duration? (optional) - The maximum time to wait for a connection. Returns: Future - Completes when pairing is successful. Throws: PairingException - If pairing fails. ConnectionException - If a connection issue occurs. PlatformException - For platform-specific errors. Notes: - On Apple and Web, it only works on devices with encrypted characteristics. - On Web/Windows and Web/Linux, it does not work for devices that use ConfirmOnly pairing. ``` -------------------------------- ### Get Bluetooth Availability Stream (Dart) Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/availabilityStream Retrieves a Stream of AvailabilityState objects, providing real-time updates on the Bluetooth availability status. This property is a static getter that delegates to the underlying platform implementation. ```Dart static Stream get availabilityStream => _platform.availabilityStream; ``` -------------------------------- ### Start BLE Scan Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle-class Initiates a scan for Bluetooth Low Energy devices. Scan results will be delivered to the onScanResult listener. This method may throw errors if Bluetooth is unavailable. 'webRequestOptions' is supported on Web only. ```APIDOC startScan({ScanFilter? scanFilter, PlatformConfig? platformConfig}) → Future ``` -------------------------------- ### WebOptions Constructor API Signature Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/WebOptions/WebOptions The API signature for the WebOptions constructor, detailing its optional parameters: optionalServices (List) and optionalManufacturerData (List), both defaulting to empty lists. ```APIDOC WebOptions({ List optionalServices = const [], List optionalManufacturerData = const [], }) ``` -------------------------------- ### Implement Custom UniversalBlePlatform Instance Source: https://pub.dev/documentation/universal_ble/latest/index This Dart code demonstrates how to create a custom implementation of `UniversalBlePlatform` by extending the base class. It then shows how to set this custom instance as the active platform implementation for `UniversalBle`, enabling mocking or custom behavior for Bluetooth operations. ```Dart // Create a class that extends UniversalBlePlatform class UniversalBleMock extends UniversalBlePlatform { // Implement all commands } UniversalBle.setInstance(UniversalBleMock()); ``` -------------------------------- ### Dart: Get companyIdRadix16 Property Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/ManufacturerData/companyIdRadix16 This Dart getter provides the implementation for `companyIdRadix16`. It converts the `companyId` integer to a hexadecimal string using `toRadixString(16)` and prepends '0x0' to form the final string representation. ```Dart String get companyIdRadix16 => "0x0${companyId.toRadixString(16)}"; ``` -------------------------------- ### UniversalBlePlatform.connect Method API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/connect Defines the signature and parameters for the `connect` abstract method in `UniversalBlePlatform`. This method is asynchronous and connects to a specified Bluetooth Low Energy device, with an optional timeout. ```APIDOC Method: connect Class: UniversalBlePlatform Return Type: Future Parameters: - deviceId: Type: String Description: The unique identifier of the BLE device to connect to. - connectionTimeout: Type: Duration? Description: An optional duration after which the connection attempt will time out. ``` -------------------------------- ### Get pairingStateStream property for BleDeviceExtension Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDeviceExtension/pairingStateStream This Dart getter provides a Stream of boolean values indicating changes in the pairing status of a BleDevice. It internally calls the 'UniversalBle.pairingStateStream' method, passing the device's ID to retrieve the stream. ```Dart Stream get pairingStateStream => UniversalBle.pairingStateStream(deviceId); ``` -------------------------------- ### BleDevice Class Constructor API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDevice-class API documentation for the BleDevice class constructor, detailing all required and optional parameters for instantiating a BleDevice object. ```APIDOC BleDevice class Constructors: BleDevice.new({ required String deviceId, required String? name, int? rssi, bool? paired, List services = const [], bool? isSystemDevice, List manufacturerDataList = const [] }) ``` -------------------------------- ### Get Detailed BLE Device Connection State Source: https://pub.dev/documentation/universal_ble/latest/index Asynchronously retrieves the detailed connection state of a BLE device. The state can be `connected`, `disconnected`, `connecting`, or `disconnecting`, providing more granular information than a simple boolean. ```Dart // Can be connected, disconnected, connecting or disconnecting BleConnectionState connectionState = await bleDevice.connectionState; ``` -------------------------------- ### Filter BLE Scan Results by Name Prefix Source: https://pub.dev/documentation/universal_ble/latest/index Illustrates the use of `withNamePrefix` to filter BLE scan results, allowing inclusion of devices with names that match or start with the provided strings. This filter is case-sensitive. ```Dart List withNamePrefix; ``` -------------------------------- ### Connect to a BLE Device Source: https://pub.dev/documentation/universal_ble/latest/index Initiates a connection to a Bluetooth Low Energy (BLE) device using the `connect()` method. This is an asynchronous operation. ```Dart await bleDevice.connect(); ``` -------------------------------- ### Dart setNotifiable Abstract Method Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/setNotifiable Abstract Dart implementation of the `setNotifiable` method. This method is declared in the `UniversalBlePlatform` class and must be implemented by concrete platform-specific classes to handle BLE notification setup. ```Dart Future setNotifiable(String deviceId, String service, String characteristic, BleInputProperty bleInputProperty); ``` -------------------------------- ### Dart Implementation Signature for UniversalBlePlatform.connect Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/connect The abstract method signature for `connect` as defined in the `UniversalBlePlatform` class. This signature specifies the method's return type, required parameters, and optional parameters, serving as a contract for platform-specific implementations. ```Dart Future connect(String deviceId, {Duration? connectionTimeout}); ``` -------------------------------- ### PlatformConfig Constructor Definition and Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/PlatformConfig/PlatformConfig Defines the constructor signature for the PlatformConfig class, allowing optional configuration for web platforms, and provides its internal Dart implementation. This constructor is part of the universal_ble package and is used to initialize platform-specific settings. ```APIDOC PlatformConfig({ WebOptions? web, }) ``` ```Dart PlatformConfig({this.web}); ``` -------------------------------- ### Get Device Pairing State Stream Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/pairingStateStream This static method of the `UniversalBle` class provides a stream that emits boolean values indicating the pairing state of a specified Bluetooth device. It internally delegates the call to the platform-specific implementation. ```APIDOC UniversalBle.pairingStateStream: Stream pairingStateStream(String deviceId) deviceId: The ID of the device for which to get the pairing state. ``` ```Dart static Stream pairingStateStream(String deviceId) => _platform.pairingStateStream(deviceId); ``` -------------------------------- ### Dart Implementation of PairingException toString Method Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/PairingException/toString This Dart code snippet provides the concrete implementation of the `toString` method for the `PairingException` class. It simply returns the `message` property of the exception, making it easy to get a descriptive string representation of the error. ```Dart @override String toString() => message; ``` -------------------------------- ### UniversalBlePlatform Class API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Defines the abstract UniversalBlePlatform class, its constructor, and properties for managing BLE events and data streams. ```APIDOC UniversalBlePlatform (abstract class) Constructors: UniversalBlePlatform.new() Properties: availabilityStream: Stream (no setter) bleConnectionUpdateStreamController: UniversalBleStreamController<({String deviceId, String? error, bool isConnected})> (final) hashCode: int (no setter, inherited) onAvailabilityChange: OnAvailabilityChange? (getter/setter pair) onConnectionChange: OnConnectionChange? (getter/setter pair) onPairingStateChange: OnPairingStateChange? (getter/setter pair) onScanResult: OnScanResult? (getter/setter pair) onValueChange: OnValueChange? (getter/setter pair) runtimeType: Type (no setter, inherited) scanStream: Stream (no setter) ``` -------------------------------- ### Dart Implementation of UniversalBle.write Method Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/write Provides the Dart implementation for the `UniversalBle.write` static method. This code demonstrates how the method queues a command to write a characteristic value to the underlying platform, handling both with and without response scenarios. ```Dart static Future write( String deviceId, String service, String characteristic, Uint8List value, { bool withoutResponse = false, }) async { await _bleCommandQueue.queueCommand( () => _platform.writeValue( deviceId, BleUuidParser.string(service), BleUuidParser.string(characteristic), value, withoutResponse ? BleOutputProperty.withoutResponse : BleOutputProperty.withResponse, ), deviceId: deviceId, ); } ``` -------------------------------- ### Dart: Get Deprecated manufacturerData Property Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDevice/manufacturerData This Dart code snippet shows the implementation of the `manufacturerData` getter. It is marked as deprecated and retrieves the first manufacturer data entry from `manufacturerDataList`, converting it to a `Uint8List` if available, otherwise returning `null`. ```Dart @Deprecated("Use `manufacturerDataList` instead") Uint8List? get manufacturerData => manufacturerDataList.isEmpty ? null : manufacturerDataList.first.toUint8List(); ``` -------------------------------- ### Dart: Get Bluetooth Device Connection Status Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDeviceExtension/isConnected This Dart code snippet defines a getter for the `isConnected` property. It asynchronously retrieves the connection state of a Bluetooth device using `UniversalBle.getConnectionState` and returns `true` if the device's state is `BleConnectionState.connected`, otherwise `false`. It's part of the `BleDeviceExtension`. ```Dart Future get isConnected async => await UniversalBle.getConnectionState(deviceId) == BleConnectionState.connected; ``` -------------------------------- ### API Documentation for UniversalBle.subscribeIndications Method Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/subscribeIndications Defines the signature and behavior of the `subscribeIndications` static method, including its return type, required parameters, and a description of its functionality. ```APIDOC UniversalBle class: static method subscribeIndications: Return Type: Future Parameters: - deviceId: String - service: String - characteristic: String Description: Set a characteristic notifiable. Updates will arrive in onValueChange listener and characteristicValueStream. Call unsubscribe to stop updates. ``` -------------------------------- ### UniversalBle Class API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle-class Detailed API documentation for the `UniversalBle` class, outlining its structure, available constructors, instance properties, methods, operators, and static properties. This includes descriptions of their purpose, return types, and any special behaviors like inheritance or stream availability. ```APIDOC Class: UniversalBle Constructors: UniversalBle.new() Properties: hashCode: int (inherited, no setter) Description: The hash code for this object. runtimeType: Type (inherited, no setter) Description: A representation of the runtime type of the object. Methods: noSuchMethod(invocation: Invocation): dynamic (inherited) Description: Invoked when a nonexistent method or property is accessed. toString(): String (inherited) Description: A string representation of this object. Operators: operator ==(other: Object): bool (inherited) Description: The equality operator. Static Properties: availabilityStream: Stream (no setter) Description: Bluetooth availability state stream onAvailabilityChange: OnAvailabilityChange? (no getter) Description: Get Bluetooth state availability. onConnectionChange: OnConnectionChange? (no getter) Description: Get connection state changes. onPairingStateChange: OnPairingStateChange (no getter) Description: Get pair state changes. onQueueUpdate: OnQueueUpdate? (no getter) Description: Get updates of remaining items of a queue. onScanResult: OnScanResult? (no getter) Description: Get scan results. onValueChange: OnValueChange? (no getter) Description: Get characteristic value updates, after calling subscribeNotifications or subscribeIndications queueType: QueueType (no getter) Description: 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. scanStream: Stream (no setter) Description: Scan Stream timeout: Duration? (no getter) Description: Set global timeout for all commands. Default timeout is 10 seconds. Set to null to disable. ``` -------------------------------- ### Specify Web Optional Services via PlatformConfig Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble To access specific services after connection on the web without applying a filter during the scan, use `PlatformConfig`. Define the desired `optionalServices` within the `WebOptions` for the `UniversalBle.startScan` method. ```Dart UniversalBle.startScan( platformConfig: PlatformConfig( web: WebOptions( optionalServices: ["SERVICE_UUID"] ) ) ) ``` -------------------------------- ### UniversalBlePlatform Default Constructor Signature Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform/UniversalBlePlatform This API documentation snippet shows the signature for the default constructor of the UniversalBlePlatform class. It is used to create a new instance of the platform-specific implementation and takes no arguments. ```APIDOC UniversalBlePlatform() ``` -------------------------------- ### UniversalBle.getConnectionState Method API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/getConnectionState Detailed API documentation for the `getConnectionState` static method of the `UniversalBle` class. It outlines the method's signature, parameters, and the expected return type and values, providing a comprehensive reference for its usage. ```APIDOC UniversalBle class: getConnectionState static method: Signature: Future getConnectionState(String deviceId) Parameters: deviceId: Type: String Description: The ID of the device whose connection state is to be retrieved. Returns: Type: Future Description: The connection state of the device. Possible states include 'Connected', 'Disconnected' (all platforms), and 'Connecting', 'Disconnecting' (Android/Apple). ``` -------------------------------- ### Dart Implementation of BleDeviceExtension.getService Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDeviceExtension/getService The Dart source code for the `getService` method. It demonstrates how the method handles service retrieval, utilizing a cache and falling back to service discovery if the cache is empty. It includes error handling for services not found. ```Dart Future getService( String service, { bool preferCached = true, }) async { List discoveredServices = []; if (preferCached) { discoveredServices = CacheHandler.instance.getServices(deviceId) ?? []; } if (discoveredServices.isEmpty) { discoveredServices = await discoverServices(); } if (discoveredServices.isEmpty) { throw ServiceNotFoundException('No services found'); } return discoveredServices.firstWhere( (s) => BleUuidParser.compareStrings(s.uuid, service), orElse: () => throw ServiceNotFoundException( 'Service "$service" not available', ), ); } ``` -------------------------------- ### universal_ble API Platform Support Matrix Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble A comprehensive table outlining the availability and support of various `universal_ble` API methods across different platforms including Android, iOS, macOS, Windows, Linux, and Web. '✔️' indicates full support, '❌' indicates no support, and '⏺' indicates partial or conditional support. ```APIDOC | API Method | Android | iOS | macOS | Windows | Linux | Web | | --- | --- | --- | --- | --- | --- | --- | | startScan/stopScan | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | connect/disconnect | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | getSystemDevices | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | discoverServices | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | read | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | write | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | subscriptions | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | pair | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ⏺ | | unpair | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ | | isPaired | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | onPairingStateChange | ✔️ | ⏺ | ⏺ | ✔️ | ✔️ | ⏺ | | getBluetoothAvailabilityState | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | | enable/disable Bluetooth | ✔️ | ❌ | ❌ | ✔️ | ✔️ | ❌ | | onAvailabilityChange | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | requestMtu | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ``` -------------------------------- ### BleCommand Constructor API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleCommand/BleCommand Defines the parameters and types for the `BleCommand` constructor in the `universal_ble` package, including required service and characteristic strings, and an optional write value. ```APIDOC BleCommand({ required String service, required String characteristic, Uint8List? writeValue, }) ``` -------------------------------- ### PlatformConfig Class API Documentation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/PlatformConfig-class Detailed API documentation for the PlatformConfig class, including its constructor, properties, methods, and operators, used for platform-specific configuration when scanning BLE devices. ```APIDOC PlatformConfig class Description: Platform specific config to scan devices Constructors: PlatformConfig.new({WebOptions? web}) Properties: hashCode: int (inherited, no setter) Description: The hash code for this object. runtimeType: Type (inherited, no setter) Description: A representation of the runtime type of the object. web: WebOptions? (getter/setter pair) Methods: noSuchMethod(Invocation invocation): dynamic (inherited) Description: Invoked when a nonexistent method or property is accessed. toString(): String (inherited) Description: A string representation of this object. Operators: operator ==(Object other): bool (inherited) Description: The equality operator. ``` -------------------------------- ### BleDevice Constructor API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDevice/BleDevice Defines the public API for creating a new `BleDevice` instance, specifying all available parameters, their types, and whether they are required or optional. This signature details how to instantiate a `BleDevice` object. ```APIDOC BleDevice({ required String deviceId, required String? name, int? rssi, bool? paired, List services = const [], bool? isSystemDevice, List manufacturerDataList = const [], }) ``` -------------------------------- ### UniversalBlePlatform Class API Reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBlePlatform-class Detailed API reference for the UniversalBlePlatform class, outlining its methods, parameters, and return types for interacting with Bluetooth Low Energy functionalities. ```APIDOC class UniversalBlePlatform: requestMtu(deviceId: String, expectedMtu: int) -> Future setNotifiable(deviceId: String, service: String, characteristic: String, bleInputProperty: BleInputProperty) -> Future startScan({scanFilter: ScanFilter?, platformConfig: PlatformConfig?}) -> Future stopScan() -> Future toString() -> String (inherited) unpair(deviceId: String) -> Future updateAvailability(state: AvailabilityState) -> void updateCharacteristicValue(deviceId: String, characteristicId: String, value: Uint8List) -> void updateConnection(deviceId: String, isConnected: bool, [error: String?]) -> void updatePairingState(deviceId: String, isPaired: bool) -> void updateScanResult(bleDevice: BleDevice) -> void writeValue(deviceId: String, service: String, characteristic: String, value: Uint8List, bleOutputProperty: BleOutputProperty) -> Future # Operators operator ==(other: Object) -> bool (inherited) ``` -------------------------------- ### Declare Bluez Plug in Linux Snapcraft YAML Source: https://pub.dev/documentation/universal_ble/latest/index This YAML snippet demonstrates how to declare the 'bluez' plug within the 'snapcraft.yaml' file for Linux applications packaged as snaps. This declaration is necessary to grant the snap access to Bluetooth functionality on the system. ```YAML ... plugs: - bluez ``` -------------------------------- ### Implement Custom UniversalBlePlatform Instance Source: https://pub.dev/documentation/universal_ble/latest/packages/universal_ble For advanced control, create a custom class that extends `UniversalBlePlatform` and implement all required commands. This custom instance can then be registered with the Universal BLE system using `UniversalBle.setInstance`. ```Dart // Create a class that extends UniversalBlePlatform class UniversalBleMock extends UniversalBlePlatform { // Implement all commands } UniversalBle.setInstance(UniversalBleMock()); ``` -------------------------------- ### Discover Services on BleDevice using BleDeviceExtension Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDeviceExtension Discovers the services offered by the device. This method is available on BleDevice and provided by the BleDeviceExtension extension. ```APIDOC BleDeviceExtension.discoverServices() Returns: Future> Description: Discovers the services offered by the device. ``` -------------------------------- ### BleService Constructor API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleService/BleService Defines the signature and parameters for the `BleService` constructor. It requires a UUID string and a list of `BleCharacteristic` objects to initialize a new BLE service instance. ```APIDOC BleService constructor: Signature: BleService(String uuid, List characteristics) Parameters: uuid: String - The UUID of the BLE service. characteristics: List - A list of characteristics associated with the service. ``` -------------------------------- ### API: BleCharacteristic.withMetaData Constructor Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleCharacteristic/BleCharacteristic.withMetaData Defines the `BleCharacteristic.withMetaData` constructor, listing its required parameters and their types for API reference. ```APIDOC BleCharacteristic.withMetaData({ required String deviceId, required String serviceId, required String uuid, required List properties, }) ``` -------------------------------- ### UniversalBle.receivesAdvertisements Static Method API Definition Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/receivesAdvertisements Defines the signature and behavior of the `receivesAdvertisements` static method within the `UniversalBle` class, including its parameters, return type, and platform-specific considerations for advertisement reception. It also notes browser compatibility and required flags. ```APIDOC UniversalBle.receivesAdvertisements: Method: static receivesAdvertisements Parameters: deviceId: Type: String Description: The ID of the device to check for advertisement support. Returns: Type: bool Description: 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 scanResult updates will be received for this device. Notes: - Requires 'chrome://flags/#enable-experimental-web-platform-features' flag on Chrome. - Not all browsers support this API. - Advertisement events may not always fire even if supported. ``` -------------------------------- ### PlatformConfig web property API reference Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/PlatformConfig/web Defines the 'web' property within the PlatformConfig class. It is a nullable WebOptions object that acts as both a getter and a setter for web-specific configurations. ```APIDOC PlatformConfig class: web property: Type: WebOptions? Description: A getter/setter pair for web-specific configurations. ``` -------------------------------- ### BleCommand Constructor Dart Implementation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleCommand/BleCommand Provides the Dart implementation details for the `BleCommand` constructor, showing how the `service`, `characteristic`, and `writeValue` parameters are assigned to instance properties. ```Dart BleCommand({ required this.service, required this.characteristic, this.writeValue, }); ``` -------------------------------- ### Dart Implementation for UniversalBle.enableBluetooth Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/UniversalBle/enableBluetooth This Dart code provides the asynchronous implementation for the `enableBluetooth` static method. It queues a command to the underlying platform to enable Bluetooth, ensuring thread safety and proper execution flow. ```Dart static Future enableBluetooth() async { return await _bleCommandQueue.queueCommand( () => _platform.enableBluetooth(), ); } ``` -------------------------------- ### Universal BLE API Platform Support Matrix (APIDOC) Source: https://pub.dev/documentation/universal_ble/latest/index This table outlines the platform compatibility for various `universal_ble` API functions across Android, iOS, macOS, Windows, Linux, and Web. It indicates which functions are fully supported (✔️), partially supported (⏺), or not supported (❌) on each platform. ```APIDOC startScan/stopScan: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ connect/disconnect: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ getSystemDevices: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ❌ discoverServices: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ read: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ write: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ subscriptions: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ pair: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ⏺ unpair: Android ✔️, iOS ❌, macOS ❌, Windows ✔️, Linux ✔️, Web ❌ isPaired: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ onPairingStateChange: Android ✔️, iOS ⏺, macOS ⏺, Windows ✔️, Linux ✔️, Web ⏺ getBluetoothAvailabilityState: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ❌ enable/disable Bluetooth: Android ✔️, iOS ❌, macOS ❌, Windows ✔️, Linux ✔️, Web ❌ onAvailabilityChange: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ✔️ requestMtu: Android ✔️, iOS ✔️, macOS ✔️, Windows ✔️, Linux ✔️, Web ❌ ``` -------------------------------- ### Discover Services on BleDevice using BleDeviceExtension Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/BleDevice-class Discovers the services offered by the device. This method is available on BleDevice and provided by the BleDeviceExtension extension. ```APIDOC BleDeviceExtension.discoverServices() -> Future> ``` -------------------------------- ### WebOptions Class API Documentation Source: https://pub.dev/documentation/universal_ble/latest/universal_ble/WebOptions-class Detailed API specification for the WebOptions class, including its constructor, properties, and inherited methods/operators. This class is used to configure options for scanning Bluetooth devices on the web, particularly for specifying optional services and manufacturer data. ```APIDOC WebOptions class Description: Web options to scan devices. Constructors: WebOptions.new({ List optionalServices = const [], List optionalManufacturerData = const [] }) optionalServices: List - A list of service UUIDs to ensure access after connecting. By default, services from scanFilter will be used. optionalManufacturerData: List - A list of CompanyIdentifier's used to add ManufacturerData in advertisement results of selected device from web dialog. By default, manufacturerData from scanFilter will be used. Properties: optionalServices: List (read/write) optionalManufacturerData: List (read/write) hashCode: int (read-only, inherited) runtimeType: Type (read-only, inherited) Methods: noSuchMethod(Invocation invocation): dynamic (inherited) toString(): String (inherited) Operators: operator ==(Object other): bool (inherited) ```