Overview:

In this guide we will discuss about Firebase messaging. And I'll try my best to clear your all confusions about Firebase Cloud Messaging. This is a very famous feature in todays application. After Adding this feature your application will be able to send custom notifications to your users. This feature is usually used when you want to inform your Users about some information. If we talk about YouTube so you will noticed when someone Upload a new video on YouTube than YouTube inform their users via Notifications. So this is the best example of Firebase Messaging in Flutter.


How to Implement Firebase Messaging in Flutter:

First of all go to Google Firebase and Login to your Account. Find the Engage Menu and Than click on Firebase messaging and Turn on this Feature from your Firebase Account. And make sure your Firebase Account is Successfully connected with your Flutter Application. 

Firebase Official Site Image while Creating Notification

Setup Firebase Messaging in Flutter Application:

After enabling the Firebase Messaging from Firebase Account open your Application in Android studio and follow these steps.

1: Add Firebase Messaging Dependency in Your Application Pub Spec file:

Go to Pub Dev official website which is specially designed by Google for Flutter Developers. Now search for Firebase messaging and copy the dependency and paste it in the Pub Spec dependency section. This dependency is creatd by Google Learn more
dependencies:
firebase_messaging: ^14.6.5


2: Write Some Code in Flutter App to activate Firebase Messaging:

Every Flutter Android Application start from main .dart file. So in this file you will see main function inside this main function add these lines of codes. These Lines of codes will help your application to show firebase messaging. 
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
That's it now your application is ready to use Firebase Messaging Feature. If you want to test this feature by sending demo Notification than Try this step.

3: Testing Firebase Messaging on Test Device:

This testing process is very important after testing the notifications you will be satisfied with this feature. And if you want to customize this feature than for more customization follow the Firebase official documentation. 
In order to show the test notifications in your app than first of all generate FMC token (Firebase Cloud Messaging) of your device. To generate FMC token write these lines of codes in your main function.
final fcmtoken  = await FirebaseMessaging.instance.getToken();
print (fcmtoken);
After adding this code in main method than restart your Flutter Android Application. Once your Android Application will restart than he will generate the Firebase Cloud Messaging Token in the Run Console Section so check the Run Console and copy the Firebase Cloud Messaging (FCM) token. Check out this image for More Info. Your FCM Token will look like this:



4: Add this Firebase Cloud Message Token in Firebase(For Testing Only):

Now If you want to test Firebase Cloud Notifications than Open your Project in Firebase which is already connected with your Flutter Application. Now click on Engage and than Click on Cloud Messaging. Now Compose your Notification. Like Add Title of Your Notification and than add body (A message that you want to convey to your users). These two things are Required for Firebase Cloud Notification. After this Add image in your Notification its not required if you don't want to add than leave it empty.
When you done click on Send Test message and than a new dialogue box will opened enter Firebase Cloud Messaging Token here. That we get from our Flutter Project in Step No 3.
Paste the FCM token and save it by clicking on + button. Than click on Test. Now Firebase will immediately send the test Notification on your Test Device. 
In this Way you will confirm is your Firebase Cloud Messaging in Flutter is working or Not. If you receive the test notification than Congratulations you've successfully implemented the Firebase Cloud messaging in Flutter Application.



How to Use Firebase Cloud Messaging in a proper way to Engage Users:

If you have a news app so this Fire Cloud Messaging feature is very useful for you. You can use this feature to engage users. How you can do this? Let's suppose if you add some news in your application and after adding some new news you want to inform your users about this than use Firebase Cloud Messaging customize this function accordingly and inform your users about new news. This Method will help you to get more attention from users.

Firebase Cloud Messaging Supported Platforms:

Firebase Cloud Messaging Supports multiple platforms Like, Website, Android, IOS, Unity. If you are working on multiple platforms than don't worry Firebase Cloud Messaging is available for almost all platforms. So feel free to use this Firebase Feature.

Firebase Cloud Messaging for Custom Users:

You can use this feature and send notifications to a custom user. Let's suppose if you want to share some important news with User John than Firebase Cloud Messaging allows you to send Notifications to specific users. If you want to send notification to any Specific user than you need to setup some important things.




When you will send the Live Notification to your users than during notifications setup Firebase Cloud messaging will ask some optional things like Android Notification Channel, Custom data, And value. Setup these all things and add Custom Key to send Notification to your Specific users. This is very useful feature like YouTube. YouTube only informs you about your subscriptions video. Like if you subscribe Flutter with NK than you will get notification only from Flutter with NK because you subscribe my channel so in this way YouTube send specific notifications to their users. You can also implement this type of feature in your Application by using this Firebase Cloud Messaging. 

How Many Notifications we can send From Firebase Cloud Messaging (Free Plan):

We know firebase provide free and paid plan Free Plan name is Spark and Paid Plan name is Blaze for Firebase database. So if you are using Free Plan in Firebase than Firebase Cloud Messaging Service allows you to send 100,000 notifications per day. But if you want to send more notifications than Buy Firebase Blaze Plan this will allows you to send more than 100,000 notifications per day. You can choose this according to your need. If your Application has Millions of Active users than definitely go with Paid Version.


How to Buy Firebase Blaze Plan and Increase Firebase Cloud Messaging Notifications:

If you want to buy Firebase Blaze Plan than Open Firebase Console and in the Menu bottom you'll see Upgrade option by default if you are using Free Version than Spark Plan is selected for you by Google for you. Click on Upgrade and a new Settings will appear on your screen. 


From this click on Select Plan and you'll be auto redirected to Console cloud Google Site. Here setup your Payment And purchase the Blaze Plan. This Blaze plan will unlocked more features for you in Firebase Console. Like Functions, Hosting and this will also increase the Database storage for you.