Skip to content

Commit 9f2a136

Browse files
committed
feat: expose unsubscribe and disconnect methods
1 parent 47aa1b8 commit 9f2a136

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/flutter_reactive_ble/lib/src/reactive_ble.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ class FlutterReactiveBle {
300300
),
301301
);
302302

303+
/// Disconnects a device with the provided id.
304+
///
305+
/// Useful for restored devices where a connection subscription is not obtained.
306+
Future<void> disconnect({required String id}) =>
307+
_blePlatform.disconnectDevice(id);
308+
303309
/// Performs service discovery on the peripheral and returns the discovered services.
304310
///
305311
/// When discovery fails this method throws an [Exception].
@@ -337,6 +343,16 @@ class FlutterReactiveBle {
337343
);
338344
}
339345

346+
/// Unsubscribes to updates from the characteristic specified.
347+
///
348+
/// Useful for restored devices that do not read as "connected"
349+
Future<void> unsubscribeToCharacteristic(
350+
QualifiedCharacteristic characteristic,
351+
) async {
352+
await initialize();
353+
return _blePlatform.stopSubscribingToNotifications(characteristic);
354+
}
355+
340356
/// Sets the verbosity of debug output.
341357
///
342358
/// Use [LogLevel.verbose] for full debug output. Make sure to run this only for debugging purposes.

0 commit comments

Comments
 (0)