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|$characteristic";
_notificationStreams[key] =
_startNotificationsEventChannel.receiveBroadcastStream().listen((event) {
if (event == null || event["status"] == "error") {
_notificationStreams[key]?.cancel();
return;
}
if (event[key]){
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"];
}