Integrations

How to Send Push Notifications in Flutter (and Lifecycle Emails) with PushFire

A step-by-step guide to send push notifications in Flutter with the pushfire_sdk package, then grow them into segmented push and email lifecycle campaigns.

EGErik Goins
Published
Updated
8 min read
Share article
Send Push Notifications in Flutter (and Lifecycle Emails) with PushFire — PushFire blog, Integrations

TL;DR: To send push notifications in Flutter with PushFire, add Firebase Cloud Messaging (FCM) to your app, run flutter pub add pushfire_sdk, and call PushFireSDK.initialize() in main() with a Public key. The SDK registers the device, asks for permission and logs the user in from Firebase Auth or Supabase Auth. Tags from the app move users into segments, and segments start push and email workflows that you build in the PushFire console. The SDK supports iOS and Android; on Flutter web its methods do nothing.

This guide shows how to send push notifications in Flutter without writing your own FCM backend. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows in one place. You write about 20 lines of Dart. PushFire stores devices and subscribers, and its visual workflow builder decides who gets which message and when. If you want the wider picture first, read the lifecycle messaging platform overview.

What you need before you start

  • A Flutter app that runs on an iOS or Android device or emulator. FCM does not work in a browser preview, and the PushFire Flutter SDK is a no-op on web.
  • A Firebase project with FCM, configured with flutterfire configure.
  • A PushFire project with your Firebase service account uploaded. The Free plan covers up to 5,000 subscribers with push workflows.
  • A Public key (pf_pk_...) from Console → Developers → API keys. Public keys can register devices, update subscribers and set tags. They cannot send messages, so they are safe to ship in an app. See Public and Secret keys.

How to send push notifications in Flutter: step by step

Step 1: Install the Flutter push notification SDK

The current version on pub.dev is 0.3.4. It works with firebase_core 3.x to 5.x.

On iOS, open ios/Runner.xcworkspace in Xcode and add two capabilities: Push Notifications and Background Modes with Remote notifications checked. Android needs no extra setup.

Step 2: Initialize PushFire in main()

initialize() requests notification permission (set requestNotificationPermission: false to ask later), gets the FCM token and registers the device. On iOS it waits for the APNs token before it asks Firebase for the FCM token, so a cold start does not fail.

Step 3: Identify the user

With AuthProvider.firebase or AuthProvider.supabase, the SDK listens to your auth state. On sign-in it logs the subscriber in with the user's ID as externalId. On sign-out it logs the subscriber out. Do not add your own auth listener.

With custom auth, use AuthProvider.none and call the SDK yourself:

The externalId matters. Your backend uses it later to send a push or an email to that user.

How do I target Flutter users with segments?

Tags describe a user. Segments group users by tag rules. Add tags from the app when something happens:

In the console, create a segment such as "Trial users who finished onboarding" with the rules plan Equals trial and onboarding Equals completed. Segments update when tags change. Read the segments guide for every operator.

How do I send lifecycle emails from a Flutter app?

You do not send lifecycle emails from the Flutter app itself, and that is the point. The app only describes the user: it logs the subscriber in with an email address and sets tags such as plan or onboarding. In the PushFire console you build a workflow whose start node is "A subscriber enters a segment". When a tag change moves a user into that segment, the workflow runs on PushFire's servers. A typical trial flow sends a welcome push, waits one day, checks a Condition node on the plan tag, and sends a reminder email through your Resend or SMTP connector if the user has not upgraded. Because the app never calls a send endpoint, it only needs a Public key, and you can change copy, timing and branching in the console without an app release. The same pattern works for win-back, cart recovery and upgrade campaigns.

Set up email once: connect Resend or SMTP, verify a sender, and publish an email layout. The workflows guide covers Wait, Condition, Multi condition and Stop nodes.

How do I send a push notification from my backend?

Some messages come from server events, such as "your order shipped". Send those from a backend with a Secret key (pf_sk_...). Never put a Secret key in a Flutter app.

Keep the Secret key on a server. Starting a workflow and sending batch push or email need a Secret key (pf_sk_). A Public key (pf_pk_) gets HTTP 403 on those calls. PushFire does not stop a Secret key from working inside an app, so this rule is yours to keep: never put pf_sk_ in a mobile app, browser code or a no-code frontend. Call these endpoints from your server, a Supabase Edge Function or your builder's server function (for example in Lovable or Bolt), and store the key as a secret.

subscriberExternalIds are the same IDs you passed as externalId. The response lists success and errors per user. A partial success returns HTTP 200; if every send fails, the API returns 400. To start a workflow for given subscribers or segments, call POST /create-workflow-execution from the same backend. The API reference lists every field.

The SDK has createImmediateWorkflowForSubscribers() and related methods, but a Public key cannot create workflow executions. Keep workflow triggers on the server or use segment-entry workflows.

Handle permission and token changes

The SDK keeps the device record current for you:

  • PushFireSDK.instance.onDeviceRegistered, onSubscriberLoggedIn, onSubscriberLoggedOut and onFcmTokenRefresh are streams you can listen to.
  • syncNotificationPermission() re-checks the OS permission and updates PushFire. The SDK also does this when the app returns to the foreground.
  • openNotificationSettings() opens the OS settings page when the user denied permission permanently.
  • setNotificationEnabled(false) lets a user turn off push in your own settings screen.
  • reset() logs out and clears all local SDK state, which is useful on shared devices.

Errors extend PushFireException. Catch PushFireApiException for API errors and PushFireNetworkException for timeouts and connectivity.

Let your AI agent do the setup

If you build with Claude Code, Cursor or Codex, install the PushFire agent skill:

The skill includes a flutter-sdk guide, so the agent writes the setup above instead of guessing. The PushFire MCP server is live too, so the agent can also build your segments and workflows. The full Flutter integration guide is Flutter push notifications. FlutterFlow users can read FlutterFlow push notification workflows.

Frequently asked questions

Is pushfire_sdk free to use?

Yes. The pushfire_sdk package is free on pub.dev, and the PushFire Free plan costs $0 for up to 5,000 subscribers with push workflows. The Pro plan costs $29 per month for up to 50,000 subscribers and adds email. You also need a Firebase project, and FCM itself has no per-message charge.

Does the PushFire Flutter SDK work on Flutter web?

No. The SDK targets iOS and Android. On Flutter web every method returns a safe default and does nothing, so your code still compiles. For browser push, register FCM web tokens through the REST API or the JavaScript guide. Test mobile push on a real device or an emulator, not a browser preview.

Which API key goes in my Flutter app?

Use a Public key that starts with pf_pk_. It can register devices, log subscribers in and manage tags, and the server enforces that limit. Keep the Secret key, pf_sk_, on your backend only. It can send batch push, batch email and workflow executions, so it must never ship in an app.

Can I send emails to Flutter users with PushFire?

Yes. Log the subscriber in with an email address, connect Resend or SMTP in the console, and add an Email Notification node to a workflow. You can also send transactional email from your backend with POST /send-batch-email-notifications, which needs an email sender ID and an email layout ID.

Do I need Firebase Auth to use the Flutter SDK?

No. AuthProvider.firebase and AuthProvider.supabase log users in automatically, which saves code. With any other auth system, set AuthProvider.none and call loginSubscriber() after sign-in and logoutSubscriber() after sign-out. You do need Firebase Cloud Messaging, because PushFire delivers every push message through FCM on both iOS and Android.

Start sending Flutter push notifications today

Create a free project at console.pushfire.app, upload your Firebase service account, and paste your Public key into PushFireConfig. The Free plan covers up to 5,000 subscribers, with push workflows, tags and segments included.

Send Push Notifications in Flutter: Step-by-Step Guide | PushFire