Docs

Flutter push notifications with the PushFire SDK

Integrations

This guide shows how to add Flutter push notifications with the official PushFire SDK, the pushfire_sdk package on pub.dev. The SDK registers the device's FCM token, identifies the subscriber, manages tags and keeps the notification permission in sync. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows behind one small API.

The SDK supports iOS and Android. On Flutter web every SDK call is a no-op, so web apps use the Web push notifications with JavaScript guide instead.

Prerequisites

  • A PushFire account and project. Create one at console.pushfire.app.
  • Firebase credentials uploaded to the project. See Create your first project.
  • A Public key (pf_pk_...) from Developers → API keys for the app. Your backend uses a Secret key (pf_sk_...). See Public and Secret keys.
  • A Flutter app connected to Firebase with flutterfire configure, which writes firebase_options.dart, google-services.json and GoogleService-Info.plist.
  • For iOS: the Push Notifications capability and Background Modes with Remote notifications enabled in Xcode, plus an APNs key uploaded to Firebase.

Install the Flutter SDK

This adds the current release (0.3.4) to pubspec.yaml. The SDK brings firebase_core, firebase_messaging, firebase_auth and supabase_flutter as dependencies, so you do not add them for PushFire.

Initialize PushFire in main.dart

Initialize Firebase first, then PushFire. PushFireSDK.initialize takes the config as a positional argument. It requests the notification permission and registers the device on first launch.

Pass the key at build time with flutter run --dart-define=PUSHFIRE_PUBLIC_KEY=pf_pk_....

Other PushFireConfig options:

  • requestNotificationPermission (default true): set false to ask later with requestNotificationPermission().
  • iosRegisterWithoutPrompt (default false): iOS only. With the prompt off, request provisional authorization so the device still gets a token.
  • timeoutSeconds (default 30) and baseUrl (default https://api.pushfire.app/functions/v1/).
  • enableLogging: logs full request bodies, including email and phone. Keep it off in release builds.

Register the device and identify the subscriber

initialize registers the device and creates an anonymous subscriber. Read the IDs when you need them:

With AuthProvider.firebase the SDK listens to FirebaseAuth.instance.authStateChanges(). On sign-in it logs the subscriber in with the user's UID as externalId, plus email, display name and phone. On sign-out it logs the subscriber out. AuthProvider.supabase does the same with Supabase.instance.client.auth, so call Supabase.initialize before PushFireSDK.initialize.

With AuthProvider.none, log in yourself after your own sign-in:

externalId is the value your backend uses later to send push and email.

Add, update and remove tags

Create each tag in Audience → Tags and copy its ID. The SDK takes the tag ID (a UUID), not the tag name. A subscriber must be logged in.

Trigger a workflow

Start workflows from your server. Send the subscriber ID from getSubscriberId() to your backend, then call the REST API there with the Secret key:

Warning: never ship pf_sk_ in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, and anyone can extract it from your app and message all your users. Start workflows and send messages from your server, a Supabase edge function or a Firebase Cloud Function.

The SDK also has createImmediateWorkflowForSubscribers, createImmediateWorkflowForSegments, the two scheduled variants and createWorkflowExecution. They are secret key only, not for production apps: with the Public key the API answers 403 Client key cannot perform this action. Use them only in internal tools that never reach users.

Often you need no call at all: a workflow can start when a subscriber enters a segment, and your app joins segments by setting tags.

Send push and email from your server

Batch push and email run on your backend with a Secret key and target the externalId values your app logged in:

Warning: never ship pf_sk_ in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, and anyone can extract it from your app and message all your users. Start workflows and send messages from your server, a Supabase edge function or a Firebase Cloud Function.

FCM accepts only string values in data, so send numbers and booleans as strings, for example "count": "3".

For complete server code, including email, see Send push notifications from Node.js or Send push notifications from Python.

Notification permission and status

The SDK re-checks the OS permission each time the app returns to the foreground and updates the device. Call syncNotificationPermission() to force that check.

Verify delivery

  1. Run the app on a real device or emulator with Google Play services. Turn on enableLogging for this test only.
  2. Sign in and confirm the subscriber in Audience → Subscribers: device, externalId and tags.
  3. Send the batch push above and watch Developers → API Messages → Push Notifications for the status.
  4. Listen to events while you test:

Troubleshooting

  • PushFireNotInitializedException: a call ran before PushFireSDK.initialize finished. Await it in main().
  • "Device not registered. Call registerDevice() first.": the device has no FCM token yet. On iOS, check the APNs key in Firebase and the capabilities. On a simulator without push support, no token arrives.
  • "No subscriber logged in" on tags: log the subscriber in first, or check that the auth provider matches your auth system.
  • 400 "Invalid tag ID": you passed the tag name. Pass the tag UUID.
  • 403 "Client key cannot perform this action": a workflow call from the app with a Public key. Move it to your backend.
  • Nothing happens on web: the SDK does not run on Flutter web.
  • Catch PushFireApiException (has statusCode), PushFireNetworkException, PushFireSubscriberException and PushFireTagException for specific handling.

FAQ

Does the PushFire Flutter SDK support web?

No. The SDK supports iOS and Android. On Flutter web, initialize logs a warning and every call returns without doing anything, so your app still compiles. For browser push, register the web FCM token through the REST API, as the JavaScript web guide shows.

Do I need firebase_messaging in my pubspec?

No. pushfire_sdk depends on firebase_core and firebase_messaging and gets the FCM token for you. You still connect the app to Firebase with flutterfire configure and call Firebase.initializeApp with your options before you initialize PushFire. Add the packages yourself only if your own code imports them.

Which API key goes in a Flutter app?

The Public key (pf_pk_). It can register devices, log subscribers in and out, update profiles and manage tags. It cannot send push, send email or start workflows, which keeps a leaked key harmless. Keep the Secret key on your server and do those actions there.

How does PushFire know who the user is?

With AuthProvider.firebase or AuthProvider.supabase, the SDK logs the subscriber in on sign-in, using the user ID as externalId. With AuthProvider.none, call loginSubscriber yourself. Your backend then targets that same externalId for batch push and email.

Next steps