Push notification in flutter

Md Sadab Wasim
Sep 6, 2018 · 2 min read

In a minute

Push Notifs Using Firebase

Before we start, make sure that your app is linked with firebase.

Then use this library in your pubspec.yaml file

firebase_messaging: ^1.0.3


We are good to go now, Let’s import the Firebase_messaging class and create an instance of it.

import ‘package:firebase_messaging/firebase_messaging.dart’;

FirebaseMessaging messaging = FirebaseMessaging();


Now, use it in our initState() method.

For Android

If you don’t want to setup messageHandler you can just use messaging.configure();

so, what is this?

we are configuring the firebase messaging, and we are also using it’s three properties to setup our messageHandler.

OnLaunch: when our app is close, and notification arrives, when you click on that notification OnLaunch get called and it just open the app from scratch(simple enough).

OnResume: when our app is running in the background, and notification arrives, when you click on that notification OnResume get called, it just resumes your app.

OnMessage: when our app is running and in the foreground, then OnMessage gets triggered.


For IOS

Requesting to show notifs.

Here, first of all we are requsting to show notification, and whatever they say yes/no, we will listen it, and act upon it.


That’s it, now you can go in your firebase console and send notifications to your users.

If you like it ❤️

Tap the clap 👏 button it motivates me to write.

Let me know, if I got something wrong 🐛

Happy coding;

INDIAN CODER

this publications posts about coding and programming stuffs.

Md Sadab Wasim

Written by

Flutter programmer; https://github.com/MDSADABWASIM Develop android apps, Founder of http://Beatless.ml

INDIAN CODER

this publications posts about coding and programming stuffs.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade