Flutter: Tips with Firebase FCM

Nunes Nelson
1 min readFeb 15, 2021

--

Hey Flutter Devs !

Today, i will share with you some tips on Firebase FCM, aka notifications !

Update app badger

When, app receive a notification while in foreground:

Same code to handle badge update on background notification.

Handle tap on notification, and redirect user

I struggle a lot with this one, cause i was trying to use this code :

But this code is only trigger when you send data message (not notification). So if you want to display real notification, it’s not the good way to handle it.

Magic happen, with this two methods:

getInitialMessage store last notification, so if app is on background, and user tap notification to open app, you will get notification content with this method.

onMessageOpenedApp is a stream which trigger when user tap, but app is running..

This is how we can handle such use case:

  • Redirect user on DM view
  • Redirect user, when other user mention him

Bonus

Example of notification :

FLUTTER_NOTIFICATION_CLICK is mandatory to enable tap on notification.

More complex version here to display notification with image :

You will need to follow this tutorial to enable it, specially in IOS : https://firebase.google.com/docs/cloud-messaging/ios/send-image?hl=en

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response