/flutterflow-integrations

FlutterFlow and Firebase Cloud Messaging integration: Step-by-Step Guide 2024

Learn how to seamlessly integrate FlutterFlow with Firebase Cloud Messaging in this easy, step-by-step guide. Enhance your app with real-time notifications today.

What is Firebase Cloud Messaging?

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution developed by Google that lets you reliably deliver messages at no cost. Previously known as Google Cloud Messaging, FCM allows you to send notifications and messages to users across various platforms such as Android, iOS, and web. It can be used to notify users of new content, or to send data to your application. FCM also provides topic messaging, which allows you to send a message to multiple devices that have opted in to a particular topic.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web or mobile app? RapidDev builds Bubble apps with your growth in mind.

Book a free No-Code consultation

How to integrate FlutterFlow with Firebase Cloud Messaging?

Step 1: Initial Setup in Firebase Console

 
  • Create a Firebase Project
    • Navigate to the Firebase Console.
    • Click “Add project” and follow the prompts to create a new project.
  • Enable Firebase Cloud Messaging
    • Within your project, click on “Project Settings”.
    • Go to the “Cloud Messaging” tab and note down your Server key and Sender ID.

Step 2: Add Your Flutter App to Firebase

 
  • Register Your App
    • In the Firebase Console, navigate to the Project Overview page.
    • Click on “Add app” and select the appropriate platform (iOS or Android).
    • Follow the on-screen instructions to download the google-services.json (for Android) or GoogleService-Info.plist (for iOS) file.
  • Add the Configuration Files to Your Project
    • Add the google-services.json file to the android/app directory.
    • Add the GoogleService-Info.plist file to the ios/Runner directory.

Step 3: Configure Your Flutter App

 
  • Android Configuration
    • Open the android/build.gradle file and add the Google services classpath inside the dependencies block:
      dependencies {
          classpath 'com.google.gms:google-services:4.3.10' // Check for updates
      }
    • In the android/app/build.gradle file, apply the Google services plugin:
      apply plugin: 'com.android.application'
      apply plugin: 'com.google.gms.google-services'
  • iOS Configuration
    • Open the ios/Podfile and add:
      platform :ios, '10.0'
      use\_frameworks!
      use_modular_headers!
      
      target 'Runner' do
        pod 'Firebase/Analytics'
        pod 'Firebase/Messaging'
      end
    • Install Pod Dependencies
      • Run pod install in the ios directory.

Step 4: Add Dependencies to Flutter Project

 
  • Update pubspec.yaml
    • Add the following dependencies in your pubspec.yaml file:
      dependencies:
        flutter:
          sdk: flutter
        firebase_core: latest_version
        firebase_messaging: latest_version
  • Run flutter pub get to install these dependencies.

Step 5: Initialize Firebase in Your Flutter App

 
  • Initialize Firebase
    • In your main.dart file, initialize Firebase:
      import 'package:flutter/material.dart';
      import 'package:firebase_core/firebase_core.dart';
      import 'package:firebase_messaging/firebase_messaging.dart';
      
      void main() async {
        WidgetsFlutterBinding.ensureInitialized();
        await Firebase.initializeApp();
        runApp(MyApp());
      }
      
      class MyApp extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return MaterialApp(
            home: Scaffold(
              appBar: AppBar(title: Text('FlutterFlow FCM Integration')),
              body: Center(child: Text('Hello World')),
            ),
          );
        }
      }

Step 6: Configure Firebase Messaging

 
  • Request Notification Permissions (iOS specific)
    • Add the following to your AppDelegate.swift file:
      import UIKit
      import Flutter
      import Firebase
      import UserNotifications
      
      @UIApplicationMain
      @objc class AppDelegate: FlutterAppDelegate {
        override func application(
          \_ application: UIApplication,
          didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
        ) -> Bool {
          FirebaseApp.configure()
          UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in }
          application.registerForRemoteNotifications()
          return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }
      }
  • Firebase Messaging Configuration in Flutter
    • Update your main.dart to handle foreground messages:
      void main() async {
        WidgetsFlutterBinding.ensureInitialized();
        await Firebase.initializeApp();
      
        FirebaseMessaging messaging = FirebaseMessaging.instance;
      
        NotificationSettings settings = await messaging.requestPermission(
          alert: true,
          badge: true,
          sound: true,
        );
      
        FirebaseMessaging.onMessage.listen((RemoteMessage message) {
          print('Got a message whilst in the foreground!');
          print('Message data: ${message.data}');
      
          if (message.notification != null) {
            print('Message also contained a notification: ${message.notification}');
          }
        });
      
        runApp(MyApp());
      }

Step 7: Send a Test Notification

 
  • Using Firebase Console
    • Navigate to the “Cloud Messaging” section within your Firebase project.
    • Click on “Send your first message”.
    • Fill out the required fields, specifying your message details.
    • Choose your app under “Target” section and click “Send test message”.
  • Verify the Notification
    • Run your Flutter app on a device or emulator.
    • Ensure that you can see the notification when the application is in the foreground or background.

Step 8: Handle Background Notifications

 
  • Configure Background Messaging in main.dart
    • Add a background message handler:
      Future \_firebaseMessagingBackgroundHandler(RemoteMessage message) async {
        await Firebase.initializeApp();
        print("Handling a background message: ${message.messageId}");
      }
      
      void main() async {
        WidgetsFlutterBinding.ensureInitialized();
        await Firebase.initializeApp();
      
        FirebaseMessaging.onBackgroundMessage(\_firebaseMessagingBackgroundHandler);
      
        runApp(MyApp());
      }

Conclusion

 

By following this guide, you should be able to successfully integrate Firebase Cloud Messaging with your Flutter application. This allows you to send and receive push notifications, thus enhancing user engagement with your app. Ensure that you test thoroughly and handle any edge cases, such as notifications received when the app is in different states (foreground, background, or terminated).

 

FlutterFlow and Firebase Cloud Messaging integration usecase

Scenario:

A fitness app startup wants to improve user engagement by sending real-time notifications to users about new workouts, challenges, and community events. They decide to use FlutterFlow to develop their mobile app and integrate Firebase Cloud Messaging (FCM) to manage and send push notifications to users.

Solution: Integrating FlutterFlow with Firebase Cloud Messaging

App Development in FlutterFlow:

  • The startup uses FlutterFlow to design a custom mobile app that includes user registration, workout tracking, challenges, and community event features.
  • They focus on creating an intuitive user interface and ensure seamless navigation within the app.

Setting Up Firebase Cloud Messaging:

  1. Firebase Project Configuration:
  • The startup creates a new Firebase project and adds the Flutter app to the project.
  • They download the google-services.json file for Android and GoogleService-Info.plist file for iOS, and integrate these into their FlutterFlow project.
  1. Adding FCM to FlutterFlow:
  • In FlutterFlow, they configure Firebase APIs, including enabling Cloud Messaging.
  • The startup ensures the necessary Flutter dependencies for Firebase and FCM are added to their project configuration.

Notification Workflow:

  • User Registration Token:

  • When users register or log in to the app, a unique FCM token is generated and saved in Firebase Firestore along with the user's profile data.

  • Send Push Notifications:

  • The startup sets up Cloud Functions in Firebase to handle event triggers. These functions will send out push notifications based on specific events (e.g., new workout added, new community event).

  • They use Firestore triggers or scheduled functions to send notifications to the relevant user segments.

Personalized Engagement:

  • Segmentation:

  • The startup segments users based on their interests, workout preferences, and community engagement.

  • FCM allows targeting specific user groups to deliver more personalized notifications.

  • Custom Messages:

  • Notifications include dynamic content, such as the user's name, to make messages more personal and engaging.

  • Rich media notifications (images or actionable buttons) are used for community events or special challenges.

Monitoring and Analytics:

  • User Engagement Tracking:
  • Firebase Analytics helps the startup track user engagement with the notifications, providing insights into which messages perform best.
  • The metrics allow the startup to continuously optimize their notification strategy, such as adjusting the timing or content of the notifications.

Benefits:

  • Enhanced User Engagement:
  • Real-time notifications keep users informed about new content and events, increasing app stickiness and user retention.
  • Efficient Communication:
  • Automated notifications reduce the manual effort for the startup, allowing them to focus more on creating content and improving the app.
  • Data-Driven Decisions:
  • Analytics provide valuable insights into user behavior, helping the startup make informed decisions on content and engagement strategies.
  • Personalization:
  • Personalized notifications make users feel more valued and connected, enhancing their overall app experience.

Conclusion:

By integrating FlutterFlow with Firebase Cloud Messaging, the fitness app startup can effectively engage users through timely and personalized notifications. This integration drives higher user retention, optimized communication efforts, and insightful data for continuous improvement.

Explore More Valuable No-Code Resources

No-Code Tools Reviews

Delve into comprehensive reviews of top no-code tools to find the perfect platform for your development needs. Explore expert insights, user feedback, and detailed comparisons to make informed decisions and accelerate your no-code project development.

Explore

WeWeb Tutorials

Discover our comprehensive WeWeb tutorial directory tailored for all skill levels. Unlock the potential of no-code development with our detailed guides, walkthroughs, and practical tips designed to elevate your WeWeb projects.

Explore

No-Code Tools Comparison

Discover the best no-code tools for your projects with our detailed comparisons and side-by-side reviews. Evaluate features, usability, and performance across leading platforms to choose the tool that fits your development needs and enhances your productivity.

Explore
Want to Enhance Your Business with Bubble?

Then all you have to do is schedule your free consultation. During our first discussion, we’ll sketch out a high-level plan, provide you with a timeline, and give you an estimate.

Book a free consultation

By clicking “Accept”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.

Cookie preferences