startNotifications method
Future<bool>
startNotifications(
- String deviceId,
- String service,
- String characteristic,
- int timeout,
- void callback(
- String result
override
Implementation
@override
Future<bool> startNotifications(
String deviceId,
String service,
String characteristic,
int timeout,
void Function(String result) callback) async {
final key =
"notification|$deviceId|${service.toLowerCase()}|${characteristic.toLowerCase()}";
_notificationStreams[key] = _startNotificationsEventChannel
.receiveBroadcastStream()
.listen((event) {
if (event == null || event["status"] == "error") {
_notificationStreams[key]?.cancel();
return;
}
if (event[key] != null) {
callback(event[key]["value"]);
}
});
final result = await _methodChannel
.invokeMethod<Map<dynamic, dynamic>?>('startNotifications', {
'deviceId': deviceId,
'service': service,
'characteristic': characteristic,
'timeout': timeout,
});
if (result == null || result["value"] == null) {
throw PlatformException(
code: "startNotifications(): error retrieving value");
}
return result["value"];
}