startNotifications method

  1. @override
Future<bool> startNotifications(
  1. String deviceId,
  2. String service,
  3. String characteristic,
  4. int timeout,
  5. void callback(
    1. 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"];
}