Flutter

Notifications & Events

Configure Flutter notifications and handle trip changes, cancellation and events.

Change or cancel a trip

Stay22.setTravelContext(...) passes partial trip data to the native SDK, which keeps earlier non-empty destination, hotel, coordinate and date values when you omit them. It does not reset the trip for you.

Clear before an unrelated trip, a cancelled trip, or a reset search:

await Stay22.clearTravelContext();
await Stay22.setTravelContext(TravelContext(address: 'Paris, France'));

Clearing removes the travel context and cancels the pending notification. A changed context can replace a pending notification; it does not stack a second one. Updating only adults or children does not change the native context signature. Clear and resend the full trip when changing guest counts alone.

Timing

Normal automatic scheduling is evaluated when the app becomes inactive or enters the background. Stay22 configures delays and frequency limits per partner. The local home-city check, cooldown, permission and server decision can hold an offer back. The operating system can show a notification later than requested.

To evaluate scheduling without waiting for the background trigger, use:

await Stay22.advanced.scheduleNotification();

This bypasses only that trigger; normal eligibility and account checks still apply. The native notifications.ensure API in newer SDK guides is not exposed by this package release.

Notification appearance

await Stay22.setNotificationConfig(NotificationConfig(
  title: 'Hotels in {destination}',
  message: 'Find a stay for {checkin}',
  actions: [NotificationAction(identifier: 'book', title: 'See deals')],
));

{destination}, {checkin} and {checkout} are filled when scheduling. Missing dates produce empty date placeholders. A new configuration replaces the previous configuration; omitted fields use defaults. A notification already scheduled keeps its text. Attachment paths must name local files; download a remote image before passing its path.

Events

final subscription = Stay22.events.listen((event) {
  switch (event) {
    case NotificationScheduled(:final destination, :final delay):
      print('$destination in ${delay.inMinutes} minutes');
    case NotificationClicked(:final destination, :final url):
      print('Tapped $destination: $url');
    case NotificationBlocked(:final reason):
      print('Blocked: $reason');
    case NotificationSkipped(:final reason):
      print('Skipped: $reason');
    default:
      break;
  }
});

Cancel subscription when your listener is no longer needed. The stream also reports location updates, shown and cancelled notifications, enabled changes and travel-context clearing. It buffers native events before the first subscriber. Use this stream rather than claiming the native SDK's single listener slot yourself.

iOS notification callbacks

The native SDK installs a notification delegate and forwards to the previous delegate. If another library owns UNUserNotificationCenter.delegate, determine whether it already forwards to Stay22 before adding another path. Duplicate forwarding can open and report a tap twice.

Check await Stay22.ownsNotificationDelegate(). A false result requires investigation of callback forwarding; it does not by itself prove taps are lost. The Flutter 1.6.0 README provides the Swift overrides for a host AppDelegate that receives those callbacks. Forward both responses and foreground presentation decisions. Android taps use the native SDK's activity.

Testing covers a short notification-and-tap check.

On this page