Notify me please!!!!

Notifications : One of the prime things, which let us know about the happenings around us…Going through my catalogue, I stumbled upon this idea and present you all 

Happy New year notification via Flutter and OneSignal….

Flutter and OneSignal notifications…

For all those, who wonder why not FCM, please refer to this article..

Begin…

For those who have faintest idea about OneSignal, no worries you are reading the correct stuff…

https://documentation.onesignal.com/docs

Things required :

  1. OneSignal Account if you do not already have one.
  2. OneSignal App ID, available in Keys & IDs

Generate Credentials

Before setting up, you must generate the appropriate credentials for the platform(s) you are releasing on:

iOS — Generate an iOS Push Certificate

Android — Generate a Google Server API Key

In this article, we would look at the Android setup.

Getting Google Server API Key

  1. Create a Firebase Project.
  2. Get your Firebase Cloud Messaging token and Sender ID..

 2.1 Click the Gear icon in the top left and select “Project settings”.

 2.2 Select the “CLOUD MESSAGING” tab.

 2.3 Check the red sections:

Flutter and OneSignal
Flutter and OneSignal
  • You’ll need your Server key and Sender ID.

3. Configure your OneSignal app’s Android platform settings

3.1 Go to Settings and press the Configure button to the right of Google Android.

OneSignal Setup
OneSignal Setup

Paste your Server Key and Sender ID in here and press Save.

OneSignal Setup..
OneSignal Setup..

Setup Android Project

https://documentation.onesignal.com/docs/android-sdk-setup

Open your app/build.gradle (Module: app) file, add the following to the very top.

Gradle
Gradle

Add the following to your dependencies section.

Gradle
Gradle

Add the following in your android > defaultConfig section.

Update PUT YOUR ONESIGNAL APP ID HERE with your OneSignal app id

Gradle
Gradle

Install the flutter package….

https://pub.dartlang.org/packages/onesignal

and import 'package:onesignal/onesignal.dart'; 

Notifications….

Create Notification
Create Notification

Initialize OneSignal using the following code:

OneSignal.shared.init("your_app_id_here");
//in case of iOS --- see below
OneSignal.shared.init("your_app_id_here", {	OSiOSSettings.autoPrompt: false,  OSiOSSettings.inAppLaunchUrl : true});

For Notification Receiving Handlers, 

OneSignal.shared.setNotificationReceivedHandler((OSNotification notification) {	// will be called whenever a notification is received});

and notification.jsonRepresentation() for the JSON format…

For Notification Opening Handlers,

OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {  // will be called whenever a notification is opened/button pressed.});

For Creating notifications, use OSCreateNotification() and to send OneSignal.shared.postNotification(notification);

Creating Push Messages..

You need to have subscribed users before sending push messages, do that by clicking the Prompt for Push permission button in the app above

Go to OneSignal Dashboard, of your app

DashBoard
DashBoard

Click on Messages…and New Push..

Create message and at the end click on confirm. It will show you a pop-up for confirmation. Click Send Message

OneSignal Notification…
OneSignal Notifications

Woo hoo!!!!!! You can see the notification…

https://github.com/AseemWangoo/flutter_programs/blob/master/OneSignal.dart

Leave a Reply

Your email address will not be published. Required fields are marked *