Beginning FlutterFire

Aug 30 2022 · Dart 2.16, Flutter 3.0, Visual Studio Code 1.69

Part 5: Add Notifications with Firebase Cloud Messaging

21. Leverage Firebase Cloud Messaging

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 20. Download Data from Cloud Storage Next episode: 22. Add Cloud Messaging to Your App

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 21. Leverage Firebase Cloud Messaging

Push Notifications are an invaluable tool to engage your users. You can inform them about a discount, your offers, updates, some new content, or any other kind of message. After all, we all want to keep users interested and engaged right?

The Firebase tool that enables sending messages and notifications to your app is called “Cloud Messaging”. Actually there are two kinds of messages you can send: Notifications or Data. You can also send both at the same time.

A Notification is a message that you show to your users on the foreground. A data message is a “silent massage”: you send key value pairs to the app and use them as it makes sense: for example, to trigger an update, or receive data that you can store locally.

The way you deal with notifications and data depends on the current state of the app: there are three states you should be aware of: Foreground, Background and Terminated.

Your app is in the foreground when it’s open and users see your widgets: in short when they are using your app. It’s in the background when the app is still open, but users don’t see your widgets. This happens for example when they press the “home” button after opening the app, of they have put another app in the foreground without closing your one. Finally, the app is terminated when it’s simply not running (this may happen when you swipe it away, or when you reboot your device).

Note that to receive notifications your app must have been opened at least once. No messages can be received until you open an app at least once.

On iOS, when users swipe away the app, it must be reopened before receiving background messages, and on Android the same happens when users close the app from the device settings: they must reopen it before receiving background messages. Also note that iOS simulators cannot receive notifications: you will need a physical device if you want to test this functionality.

To sum it up: with Firebase Cloud Messaging you can send notifications and data to your app from the cloud. The way you deal with those messages depends on the state of your app, and there are also cases where apps won’t receive messages, even if you correctly sent them. OK, let’s add FirebaseMessaging to your app next!