setEventHandlers static method

void setEventHandlers({
  1. void pushOpenedHandler(
    1. KumulosPushNotification
    )?,
  2. void pushReceivedHandler(
    1. KumulosPushNotification
    )?,
  3. void inAppDeepLinkHandler(
    1. Map<String, dynamic>
    )?,
  4. void deepLinkHandler(
    1. KumulosDeepLinkOutcome
    )?,
})

Implementation

static void setEventHandlers(
    {void Function(KumulosPushNotification)? pushOpenedHandler,
    void Function(KumulosPushNotification)? pushReceivedHandler,
    void Function(Map<String, dynamic>)? inAppDeepLinkHandler,
    void Function(KumulosDeepLinkOutcome)? deepLinkHandler}) {
  _pushOpenedHandler = pushOpenedHandler;
  _pushReceivedHandler = pushReceivedHandler;
  _inAppDeepLinkHandler = inAppDeepLinkHandler;
  _deepLinkHandler = deepLinkHandler;

  if (pushOpenedHandler == null &&
      pushReceivedHandler == null &&
      inAppDeepLinkHandler == null &&
      deepLinkHandler == null) {
    _eventStream?.cancel();
    _eventStream = null;
    return;
  }

  if (_eventStream != null) {
    return;
  }

  _eventStream = _eventChannel.receiveBroadcastStream().listen((event) {
    String type = event['type'];
    Map<String, dynamic> data = Map<String, dynamic>.from(event['data']);

    switch (type) {
      case 'push.opened':
        _pushOpenedHandler?.call(KumulosPushNotification.fromMap(data));
        return;
      case 'push.received':
        _pushReceivedHandler?.call(KumulosPushNotification.fromMap(data));
        return;
      case 'in-app.deepLinkPressed':
        _inAppDeepLinkHandler?.call(data);
        return;
      case 'deep-linking.linkResolved':
        _deepLinkHandler?.call(KumulosDeepLinkOutcome.fromMap(data));
        return;
    }
  });
}