Skip to content

[Various]Expose notification delivery and response timestamps to close issue #2780 - #2791

Open
ventisep wants to merge 5 commits into
MaikuB:masterfrom
ventisep:feature/notification-delivery-reponse-timestamps
Open

[Various]Expose notification delivery and response timestamps to close issue #2780#2791
ventisep wants to merge 5 commits into
MaikuB:masterfrom
ventisep:feature/notification-delivery-reponse-timestamps

Conversation

@ventisep

@ventisep ventisep commented Jun 28, 2026

Copy link
Copy Markdown

Fixes #2780

Summary

Adds optional notification timing fields to NotificationResponse:

  • notificationDeliveredAt: the time the OS delivered the notification, where available.
  • responseReceivedAt: the time the native plugin received the notification response callback.

These fields are currently populated on iOS and macOS using Apple’s UserNotifications APIs.

Motivation

Apps can receive notification responses later than the user interaction, especially when handling notification actions after the app/background isolate has been started.

Previously, apps that needed to record when a notification was delivered or when the native response callback was received had to fall back to the time Dart processed the callback. That can be inaccurate if Dart handling is delayed.

This change exposes the native timing information so apps can distinguish:

  • when the notification was delivered
  • when the native response callback was received
  • when Dart eventually processed the response

The new fields are nullable, so existing platforms and existing callers remain backwards compatible.

Implementation notes

  • Adds nullable notificationDeliveredAt and responseReceivedAt fields to the platform interface NotificationResponse.
  • iOS uses UNNotification.date for notificationDeliveredAt.
  • iOS captures responseReceivedAt once when userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is invoked.
  • macOS mirrors the same behavior using UNNotification.date and the native notification response delegate callback time.
  • Dart method-channel parsing converts epoch millisecond values into nullable DateTime fields.
  • Background callback dispatching also maps the new fields into NotificationResponse.

Testing

Tested using:

  • melos bootstrap
  • melos run analyze
  • melos run test:unit <default>

Also validated manually on a physical iPhone with a repeating local notification action. The response included:

  • notificationDeliveredAt=2026-06-28T13:01:00Z
  • responseReceivedAt=2026-06-28T13:02:12.593Z (1 minute after notification delivered when user selected an action)

Dart processing occurred later at 2026-06-28T13:03:12Z, (1 minute later when the user launched the dart app) confirming that the new fields preserve OS/native timing independently of delayed Dart processing.

Comment thread flutter_local_notifications/lib/src/callback_dispatcher.dart Outdated
@ventisep

Copy link
Copy Markdown
Author

That changes to the dismissal flow clashed with some of the changes for introducing the timestamps for exposing notification delivery and response timestamps. I have now merged the latest master and retested using the unit and integration tests which all pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the notification delivery timestamp in NotificationResponse

2 participants