Push Notification using Amazon Pinpoint in Flutter

Monikinderjit Singh
Code Well Mobile
4 min readAug 26, 2021

--

Push Notifications using aws pinpoint service in flutter By Monik

Amazon Web Services, in early 2021, extended its support for Flutter, which is quite amazing and many new startups have started to use AWS in their flutter applications due to its ease of scalability and support. Amazon Web Service offers a wide variety of options for Flutter, but we’re going to focus on Amazon Pinpoint Service today.

Amazon Pinpoint allows users to send push notifications to multiple recipients. To increase sales, companies and organisations can use marketing campaigns to contact their clients.

Let’s figure out how to integrate this into your Flutter application.

What we are going to use💻?

To start, we need to install the following packages:

Setup Amplify Pinpoint

  1. To install Pinpoint in your Amplify project, you will need to add Amplify analytics service to your Flutter project.
  2. Run amplify add analytics in your terminal (Make sure you are at root of the project)

3. Select Amazon Pinpoint service and then give a name to your pinpoint service resource.

4. Press Y and then click enter. Your Amazon Pinpoint service will be added locally.

5. Now, to publish it in the cloud, run amplify push.

Point to be noted: It takes time for Amazon analytics to start recording the events. For me, I was able to record events the next morning.

To send notifications from Pinpoint, we will need to set up a module that will interact with the app to show the notification. To fulfil this, we are going to use Firebase Cloud Messaging service which will send our notification triggered from Amazon Pinpoint to the user.

Set up Firebase Cloud Messaging

Firebase Console Setup:

  1. Open Firebase Console
  2. Click on Create Project

3. Give a name to your project and press continue.

4. Make sure analytics is enabled and then press continue.

5. Select your country and then create your project.

6. Register your app and follow the steps described there to successfully register the app.

Extra focus on initializing Firebase SDK and google-services.json file

7. After your app has been registered, go to Engage->Cloud Messaging.

Let’s write some code

Make a file named notifications.dart and add the following file. In this file, we are handling our notifications from the Amazon Pinpoint service (For more information related to this file, read the documentation).

In main.dart file, call this function _configureAmplify() inside init state

and add these lines in main() function(You can read more about handling messages in the FlutterFire documentation here).

It’s all. Ohh, wait. Let’s check how to trigger our notification from Amazon Pinpoint Service.

Make a notification from Amazon Pinpoint service webpage

  1. Go to your Pinpoint service page from your Amplify admins page and then click on the Pinpoint service you created. Click on Settings->Push notifications and enable Firebase Cloud Messaging (FCM). After enabling, there will be a green tick as shown below.

2. Go to Test Messaging and click on Push Notifications. To send a message we will be requiring a Google device token which we are getting using the getToken() function in the requirements.dart file. Without this token, we will not be able to send our message. Write this token inside the Device tokens field.

3. Write a message, add a picture URL and send this to the user.

Kudos 🎉🎉

Congratulations to everyone who was able to send their first pinpoint service to trigger the notification. Despite it being a long tutorial, you all made it to the end.

Little Bit About Me🧑‍💻🧑‍💻🧑‍💻

Hey developers, I’m Monikinderjit Singh, working on Flutter for more than a year now. My interest in cloud technology is fueled by my need to learn more about it. I am currently new to Hashnode (this is my second blog post). I would appreciate you giving it a like if you find it interesting and leaving a comment if you have a better solution for this topic. It would be awesome if you could give me some feedback on improving my content. You can connect with me on my Twitter, Github and LinkedIn .

Originally published at https://monik.hashnode.dev.

--

--

Monikinderjit Singh
Code Well Mobile

Flutter Developer | DevOps Learner | Cloud Enthusiastic