setNotificationListener static method

dynamic setNotificationListener({
  1. dynamic onReceived(
    1. NotificationData?
    )?,
  2. dynamic onClicked(
    1. NotificationData?
    )?,
  3. dynamic onDismissed(
    1. NotificationData?
    )?,
  4. dynamic onButtonClicked(
    1. NotificationData?,
    2. NotificationButtonData?
    )?,
  5. dynamic onCustomContentReceived(
    1. String
    )?,
  6. bool applicationOverridden = false,
})

Set callbacks for different types of events for notifications (in foreground or when app is open in the background) onReceived is called when notification was received. onClicked is called when notification was clicked. onDismissed is called when notification was swiped away. onButtonClicked is called when notification contains button and a button was clicked. onCustomContentReceived is called when notification includes custom json. It will a json in string format. applicationOverridden : If you have added android:name="com.pushpole.sdk.flutter.PushPoleApplication" to your AndroidManifest application attribute, the callbacks will be callable since user starts the app. But if not, callbacks will be available when you call setNotificationListener and before that callbacks won't work. This doesn't make so much difference. But in future case when Flutter added background fcm support, this can make difference.

Implementation

static setNotificationListener(
    {Function(NotificationData?)? onReceived,
    Function(NotificationData?)? onClicked,
    Function(NotificationData?)? onDismissed,
    Function(NotificationData?, NotificationButtonData?)? onButtonClicked,
    Function(String)? onCustomContentReceived,
    bool applicationOverridden: false}) {
  _receiveCallback = onReceived;
  _clickCallback = onClicked;
  _dismissCallback = onDismissed;
  _buttonClickCallback = onButtonClicked;
  _customContentCallback = onCustomContentReceived;
  _channel.setMethodCallHandler(_handleMethod);
  if (!applicationOverridden) {
    _channel.invokeMethod("PushPole#initNotificationListenerManually");
  }
}