Skip to content

Commit

Permalink
Release 1.31.6
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Jan 6, 2024
1 parent 410db2c commit 9816e11
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.31.6
* **[Feature]** add `cancelWhenScanComplete` convenience function

## 1.31.5
* **[Improve]** Updated README & Example app

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ if (await FlutterBluePlus.isSupported == false) {
// handle bluetooth on & off
// note: for iOS the initial state is typically BluetoothAdapterState.unknown
// note: if you have permissions issues you will get stuck at BluetoothAdapterState.unauthorized
FlutterBluePlus.adapterState.listen((BluetoothAdapterState state) {
var subscription = FlutterBluePlus.adapterState.listen((BluetoothAdapterState state) {
print(state);
if (state == BluetoothAdapterState.on) {
// usually start scanning, connecting, etc
Expand All @@ -135,6 +135,9 @@ FlutterBluePlus.adapterState.listen((BluetoothAdapterState state) {
if (Platform.isAndroid) {
await FlutterBluePlus.turnOn();
}
// cancel to prevent duplicate listeners
subscription.cancel();
```

### Scan for devices
Expand All @@ -158,6 +161,9 @@ var subscription = FlutterBluePlus.onScanResults.listen((results) {
onError: (e) => print(e),
);
// cleanup: cancel subscription when scanning stops
FlutterBluePlus.cancelWhenScanComplete(subscription);
// Wait for Bluetooth enabled & permission granted
// In your real app you should use `FlutterBluePlus.adapterState.listen` to handle all states
await FlutterBluePlus.adapterState.where((val) => val == BluetoothAdapterState.on).first;
Expand All @@ -168,9 +174,6 @@ await FlutterBluePlus.startScan(withServices:[Guid("180D")], timeout: Duration(s
// wait for scanning to stop
await FlutterBluePlus.isScanning.where((val) => val == false).first;
// cancel to prevent duplicate listeners
subscription.cancel();
```

### Connect to a device
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_blue_plus
description: Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, and MacOS.
version: 1.31.5
version: 1.31.6
homepage: https://github.com/boskokg/flutter_blue_plus

environment:
Expand Down

0 comments on commit 9816e11

Please sign in to comment.