FlutterBleLib icon indicating copy to clipboard operation
FlutterBleLib copied to clipboard

Notify the user when notifications are actually turned on

Open mikolak opened this issue 5 years ago • 0 comments

Modify .monitorCharacteristic() methods to accept additional callback with an argument of type Future<void>. This way the user of the library is able run logic depending on the notification being turned on.

Proposed API change:

class Peripheral {
  ...
  Stream<CharacteristicWithValue> monitorCharacteristic(
    String serviceUuid,
    String characteristicUuid, {
    String transactionId,
    void Function(Future<void>) onNotificationsTurnedOnCallback = (_) {},
  })
  ...
}

Example:

async onNotificationsTurnedOn() {
  await peripheral.writeCharacteristic(...);
}
...

peripheral.monitorCharacteristic(
  "<serviceUuid>", 
  "<characteristicUuid>", 
  onNotificationsTurnedOnCallback = async (future) { 
    await future; 
    onNotificationsTurnedOn(); 
  }).listen((value) => print(value););

mikolak avatar Jun 23 '20 08:06 mikolak