OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[Bug]: Notification still showing after calling event.preventDefault()

Open ilyasarafathemvigo opened this issue 1 year ago • 8 comments
trafficstars

What happened?

onesignal_flutter 5.0.4 using this SDK version after calling this preventDefault() function still notification is showing

Steps to reproduce?

1. Add latest version of one signal flutter SDK (5.0.4) 
2. Send notification to a device.
3. Inside "addForegroundWillDisplayListener" listener call "event.preventDefault()" function to hide notification
4. Observe the result.

What did you expect to happen?

No need to show the particular notification after calling this function (preventDefault(+)

OneSignal Flutter SDK version

5.0.4

Which platform(s) are affected?

  • [ ] iOS
  • [X] Android

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ilyasarafathemvigo avatar Jan 15 '24 07:01 ilyasarafathemvigo

@Nightsd01 @Jeasmine please go through the bug. I have the same issue

EM-Sabeel avatar Jan 15 '24 10:01 EM-Sabeel

@ilyasarafathemvigo Thank you for reporting we are investigating

emawby avatar Jan 17 '24 18:01 emawby

@ilyasarafathemvigo @EM-Sabeel I am not able to reproduce this issue, but I did notice some incorrect behavior when using "hot reload". It seemed that when I changed the behavior in the foreground display listener it wasn't being respected unless I did a full app reload instead of a hot reload. Are you not able to get preventDefault() to work even on full reloads? Also ensure that you aren't calling notification.display() after preventDefault()

emawby avatar Jan 17 '24 19:01 emawby

Without hot reload am getting this error @emawby

ilyasarafathemvigo avatar Jan 18 '24 09:01 ilyasarafathemvigo

Hi @ilyasarafathemvigo, We haven't been able to reproduce, can you answer some additional questions?

  1. Is this consistently happening 100% of the time?
  2. Is this only happening in Android, not iOS?
  3. Can you share your setup code where you set addForegroundWillDisplayListener?
  4. Can you share logs when the device receives the notification? Thank you!

nan-li avatar Jan 30 '24 23:01 nan-li

I have the same problem when preventDefault is called after an async time gap. Is this a bug or intended behaviour?

christofkost avatar Feb 21 '24 10:02 christofkost

Hi @christofkost, You must call preventDefault by the time the callback returns. This is intended behavior as the listener cannot know about the async logic you plan to do later.

nan-li avatar Mar 22 '24 21:03 nan-li

Same issue here, I want receive notification but not to show that notification so i must use event.preventDefault(); but even after this i am still getting notification . This is the code that i am using: OneSignal.Notifications.addForegroundWillDisplayListener((event) async { event.preventDefault(); final jsonrep = event.notification.jsonRepresentation(); final json = jsonDecode(jsonrep); print(json); //awesome_notifications await NotificationUtils().createLocalInstantNotification(json); }); @emawby , If you got some solution please inform @nan-li @christofkost @ilyasarafathemvigo @EM-Sabeel .

tarun824 avatar Apr 09 '24 11:04 tarun824