listenNotificationState method

StreamSubscription listenNotificationState(
  1. void onStateChange(
    1. KGattDevice device,
    2. bool enabled
    )
)

监听主机设备订阅或取消订阅Notification

Implementation

StreamSubscription listenNotificationState(void Function(KGattDevice device, bool enabled) onStateChange) {
  return KGattHandler()
      .eventStream
      .where((event) => event['event'] == 'NotificationStateChange' && event["entityId"] == entityId)
      .listen((event) {
    final device = KGattDevice.fromMap(Map.from(event['device']));
    onStateChange(device, event['enabled']);
  });
}