Closed katilley closed 3 years ago
resolved this. may have been a sequencing issue. Added a .then and it seems to work....
Future<void> unsubscribeToServices(
List<DeviceManagement> deviceList, int deviceIndex) async {
print('Unsubscribing');
await _receivedNewAlertData.cancel().then((valueNotUsed) async {
deviceList[deviceIndex].subscribed = false;
//
// Read CCCD to confirm unsubscribe was successful:
DescriptorWithValue data = await deviceList[deviceIndex]
.foundBleAlertDevices
.readDescriptor(
"00001811-0000-1000-8000-00805f9b34fb",
"00002a46-0000-1000-8000-00805f9b34fb",
"00002902-0000-1000-8000-00805f9b34fb",
)
.then((data) {
print('CCCD cleared? read = ${data.value}');
return data;
});
});
For monitoring characteristics the documentation says that "Cancelling the last subscription disables the notifications/indications on this characteristic." Using .cancel() on the stream only cancels the stream notification in the app but the console shows the notification still being registered and a read of the underlying descriptor shows the notification is still set.
I/flutter (22585): CCCD cleared? read = [1, 0]
Is there some other way I'm supposed to cancel notifications?