Flutter Integration
Integrate Entrig in 5 steps:
Install → Setup (iOS only) → Initialize → Register → Handle
Installation
Add the package to your pubspec.yaml:
dependencies: entrig: ^1.0.0Platform Setup
Android
No additional setup required.
iOS
Run the setup command from your project root:
dart run entrig:setup iosThis configures AppDelegate.swift, Runner.entitlements, and Info.plist with the required push notification settings.
If Runner.entitlements does not exist, create it manually in Xcode by adding the Push Notifications capability under Runner target > Signing & Capabilities.
Initialization
Initialize Entrig in main() before runApp:
await Entrig.init(apiKey: 'YOUR_ENTRIG_API_KEY');Your API key is available in the Entrig dashboard under project settings.
Registering Devices
Call Entrig.register() with the user’s ID when they sign in, and Entrig.unregister() when they sign out.
// On sign inEntrig.register(userId: userId);
// On sign outEntrig.unregister();The userId you pass here must match the user identifier field configured in your notification in the Entrig dashboard. If they do not match, Entrig cannot resolve the recipient.
We recommend using the Supabase Auth user ID (session.user.id) as the userId. It is stable, always available when using Supabase Auth, and is typically the ID that other tables in your database already reference.
Handling Notifications
When a notification arrives, your app can be in one of three states:
- Foreground - app is open and visible
- Background - app is running but not visible
- Terminated - app is fully closed
Entrig handles displaying notifications in all three states. The only thing you need to handle is what happens when the user taps a notification.
To handle notification taps, listen to onNotificationOpened:
Entrig.onNotificationOpened.listen((NotificationEvent event) { // navigate based on event.type or event.data});By default, notifications are also shown as a banner when the app is in the foreground. You can turn this off:
await Entrig.init( apiKey: 'YOUR_ENTRIG_API_KEY', showForegroundNotification: false,);NotificationEvent fields:
| Field | Description |
|---|---|
title | Notification title |
body | Notification body |
type | Custom type identifier set in the dashboard |
data | Custom payload data from your database |
Permission Handling
By default, Entrig.register() requests notification permission automatically. To handle permissions yourself:
await Entrig.init( apiKey: 'YOUR_ENTRIG_API_KEY', handlePermission: false,);
// Then request manually before registeringawait Entrig.requestPermission();