Skip to content

Push Notifications

ShipFlutter uses Firebase Cloud Messaging (FCM) to handle push notifications across all platforms. The notifications module provides a complete setup for handling notifications in the foreground, background, and when the app is terminated.

Setup

  1. Follow the FCM setup guide in the Firebase Console

  2. For iOS, upload your APNs certificate:

  3. For Android, the setup is handled automatically by the Firebase CLI

  4. For Web, add your Firebase web configuration to app/web/firebase-messaging-sw.js

Notification Service

The NotificationsService handles device registration and message handling:

// Request permission and register device
final device = await notificationsService.instance.register(
requestPermission: true, // To automatically request permission if needed
);
// Get FCM token
print('Token: ${device.token}');

Local Notifications

When the app is in the foreground, FCM messages are displayed using flutter_local_notifications:

// Display notification with optional deep link
await notification.display(link: message.getLink());

The notification configuration includes:

  1. Custom notification channel for Android
  2. Sound and badge support for iOS
  3. Deep link handling when tapped

Notifications Settings

The settings_view.dart contains a notifications tile that handles permission requests and device registration:

  1. Permission requests
  2. Device registration
  3. Opening system settings
  4. Loading states

Background Handling

Background messages are handled in notifications_background.dart:

@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(
RemoteMessage message,
) async {
// Initialize Firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// TODO: Handle the message
print('Handling background message: ${message.messageId}');
}