Scan BLE device
Sets scan listener
When the scan is enabled, the scan event listener stream bleScanEveStm will be triggered, and the scan result will be returned through the bleScanEveStm listener stream and stored in the “event” as a BleScanEvent object.
_blePlugin.bleScanEveStm.listen(
(BleScanBean event) async {
/// Do something with new state
});
Callback Description:
BleScanBean:
callback value | callback value type | callback value description |
---|---|---|
isCompleted | bool | is completed |
address | String | Device address |
mRssi | int | equipment rssi |
mScanRecord | List< int > | Bluetooth scan device record |
name | String | Equipment name |
Start scan
When scanning Bluetooth devices, it will first obtain the open status of Bluetooth, and only when the permission is allowed and the Bluetooth is turned on can start normal scanning.
_blePlugin.startScan(10*1000).then((value) => {
/// Do something with new state
}).onError((error, stackTrace) => {
});
Parameter Description :
- The scan duration can be set in milliseconds.
- Since Bluetooth scanning is a time-consuming operation, it is recommended to set the scanning time to 10 seconds.
Cancel scan
Turn off the bluetooth scan, and the result listens to the callback through the bleScanEveStm data stream.
_blePlugin.cancelScan;