Dreamflow + Pushfire SDK
Guide: Integrating PushFire SDK in DreamFlow for Push Notification
The pushfire_sdk uses Firebase Cloud Messaging (FCM) as its backbone to deliver notifications. This means our first priority is to get Firebase set up correctly.
Step 0: Prerequisites - Firebase Project Setup
Before you can use pushfire_sdk, you must create and connect a Firebase project. This is the backbone of your push notification system.
Step 1: Create a Firebase Project
Go to the Firebase Console.
Click "Add project".
Enter a name for your project (e.g., "MyDreamFlowApp").
Follow the on-screen steps. It's recommended to enable Google Analytics for your project.
Once your project is created, you will be taken to the project dashboard. Leave this browser tab open.
Step 0.1: Connect Firebase Within Your DreamFlow App
DreamFlow has a built-in integration that makes connecting to Firebase simple and automatic. You only need to be the owner of the project to do this.
In your DreamFlow project, in the sidebar, select FIrebase.

Click the "Connect" button to link your Firebase account to DreamFlow.
A pop-up will appear. Select your google account.
Select the Firebase project you just created from the dropdown list.

Click "Continue".
This process may take 2-5 minutes. Once it's done, you'll see a confirmation message. Then click on "Configure Firebase". DreamFlow will now automatically configure your Firebase project by:
Adding Android and iOS apps to your Firebase project.
Using your DreamFlow App's Package Name and Bundle ID.
Generating and linking the necessary configuration files (google-services.json & GoogleService-Info.plist) for you.

Step 1: Implementation - Pushfire in DreamFlow.
First, let's add the necessary packages to your project. Open your pubspec.yaml file and add the following lines under dependencies:
Step 2: Create a Central "Remote Control" for PushFire
What this does:
This command creates a single, organized file to manage all PushFire functionalities. Think of it as a central remote control for all push notification actions. This keeps your project clean and easy to manage.
Go over code view -> lib/services/ right click and select "add new file"
lib/services/pushfire_service.dart

Paste the following code block into that new file. This code will be our central service for handling all push notifications:
Step 3: Turn On the PushFire Service When Your App Starts
1. App Initialization
- initialize()
What it does: Turns on the PushFire service when your app starts. This must be called once before any other function will work.
Dreamflow Prompt:
"I need you to modify my lib/main.dart file.
Import the pushfire_service.dart file.
Create a single, globally accessible instance of the PushfireService.
Inside the main function, call the initialize method on our service instance before runApp(). Use 'YOUR_API_KEY_HERE' for the API key."
2. Managing the Current User Session
- loginUser()
What it does: Associates the device with a specific user account using your unique ID for them. This tells PushFire who is currently using the app.
Dreamflow Prompt:
"Using my PushfireService instance, call the loginUser function. The externalId is 'user-123', the name is 'John Doe', and the email is 'john.doe@example.com'."
- isUserLoggedIn()
What it does: Checks if a user session is currently active on the device. Returns true or false.
Dreamflow Prompt:
"Use my PushfireService to call isUserLoggedIn and store the result in a new boolean variable named isLoggedIn."
- logoutUser()
What it does: Disconnects the current user from the device. Call this when the user signs out of your app.
Dreamflow Prompt:
"Using my PushfireService instance, call the logoutUser function. After user taps X button"
Actions for the Currently Logged-In User
- getCurrentUser()
What it does: Fetches all available details (like PushFire ID, name, email) for the user who is currently logged in.
Dreamflow Prompt:
"Use my PushfireService instance to call getCurrentUser and store the result in a new variable named currentUser."
- updateUser()
What it does: Changes the profile details of the user who is currently logged in.
Dreamflow Prompt:
"Using my PushfireService instance, call the updateUser function to change the current user's name to 'Johnathan Doe'."
Tag Management
The key for all tag functions (e.g., 'region', 'interests') corresponds to the Tag ID in your PushFire dashboard.
Where to find the Tag ID: Pushfire Dashboard > Audience > Tags > #yourtag

- addTag() / addTags()
What it does: Creates new descriptive tags for the current user. This should be used when you are assigning a tag for the very first time (e.g., during onboarding or after a specific first-time action).
Dreamflow Prompts:
(Single Tag): "Use my PushfireService instance to call the addTag function. The key should be '#tagIDfromPushfire' and the value should be 'USA'."
(Multiple Tags): "Use my PushfireService instance to call addTags. Add a tag with key '#tagIDfromPushfire' and value 'sports', and another with key '#tagID2fromPushfire' and value 'free_trial'."
- updateTag() / updateTags()
What it does: Modifies the value of existing tags for the current user. Use this when a user's status or preference changes (e.g., they upgrade their plan or change a setting).
Dreamflow Prompts:
(Single Tag): "Use my PushfireService instance to call the updateTag function. The key should be '#tagIDfromPushfire' and the new value should be 'finance'."
(Multiple Tags): "Use my PushfireService instance to call updateTags. Update the tag with key '#tagIDfromPushfire' to 'premium' and the tag '#tagID2fromPushfire' to 'technology'."
- removeTag() / removeTags()
What it does: Deletes one or more tags and their associated values from the currently logged-in user. Use this when a characteristic no longer applies.
Dreamflow Prompts:
(Single Tag): "Use my PushfireService instance to call the removeTag function for the key '#tagIDfromPushfire'."
(Multiple Tags): "Use my PushfireService instance to call removeTags. Remove the tags with the keys 'region' and '#tagIDfromPushfire'."
4. Triggering Automated Workflows
- triggerWorkflowForUsers()
What it does: Immediately starts a messaging campaign for a specific list of PushFire subscriber IDs.
Dreamflow Prompt:
"Use my PushfireService to call triggerWorkflowForUsers. The workflow ID is 'welcome-campaign' and it should be sent to the subscriber IDs stored in my list variable named targetSubscribers."
- triggerWorkflowForSegments()
What it does: Immediately starts a messaging campaign for users who belong to one or more Segments you created in your PushFire dashboard.
Dreamflow Prompt:
"Use my PushfireService to call triggerWorkflowForSegments. The workflow ID is 'new-feature-promo' and it should be sent to the segments 'premium-users' and 'active-last-7-days'."
5. Getting Device & Subscriber IDs
- getDeviceId()
What it does: Gets the unique ID that PushFire has assigned to the current device.
Dreamflow Prompt:
"Use my PushfireService instance to call getDeviceId and print the result to the console."
- getSubscriberId()
What it does: Gets the unique ID that PushFire has assigned to the currently logged-in user.
Dreamflow Prompt:
"Use my PushfireService instance to call getSubscriberId and store the result in a variable named pushfireUserId."
6. Listening to Real-Time Events
- onUserLoggedIn
What it does: Allows you to run code automatically at the exact moment a user successfully logs in.
Dreamflow Prompt:
In my widget's initState, I need to listen for when a new user logs in. Use the onUserLoggedIn stream from my PushfireService. When a user logs in, print a message to the console saying 'Welcome, [user name]!'.