avatarAseem Wangoo

Summary

The web content provides a comprehensive guide on integrating OneSignal push notifications with a Flutter application, including setup instructions, code examples, and explanations for both Android and iOS platforms.

Abstract

The provided web content serves as an all-encompassing resource for Flutter developers looking to implement push notifications using OneSignal. It begins by introducing the concept of notifications and their importance in user engagement, then proceeds to explain the advantages of using OneSignal over Firebase Cloud Messaging (FCM) for push notifications. The article guides readers through the process of setting up a OneSignal account, generating necessary credentials for Android and iOS, and configuring the Flutter project to integrate OneSignal's SDK. It includes detailed instructions on initializing OneSignal in a Flutter app, handling received notifications, and creating custom notifications. Additionally, the content covers how to prompt users for push notification permissions, create push messages from the OneSignal dashboard, and send them to subscribed users. The article also points to related Flutter resources and invites contributions to the Flutter community through the Flutter Pub publication.

Opinions

  • The author suggests that OneSignal is a preferable choice for push notifications compared to FCM, referencing an article that discusses the benefits of OneSignal.
  • The author expresses enthusiasm for the new year and the potential of Flutter and OneSignal to enhance user engagement through notifications.
  • The article is written with the assumption that some readers may be unfamiliar with OneSignal, indicating a consideration for both novice and experienced developers.
  • The inclusion of links to further reading and related articles demonstrates the author's intent to provide a holistic learning experience and encourage community engagement.
  • The author's use of phrases like "Happy New year notification" and "Woo hoo!!!!!! You can see the notification" conveys a positive and celebratory tone towards the achievements and possibilities of implementing notifications in Flutter apps.

Flutter and OneSignal Notifications

Flutter and OneSignal Notifications

All in one Flutter Resource: https://flatteredwithflutter.com/send-notifications-in-flutter/

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
  • 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

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

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

Add the following to your dependencies section.

Gradle

Add the following in your android > defaultConfig section.

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

Gradle

Install the flutter package….

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

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

Notifications….

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

Click on Messages…and New Push.

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

OneSignal Notification…

Articles related to Flutter:

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

The Flutter Pub is a medium publication to bring you the latest and amazing resources such as articles, videos, codes, podcasts etc. about this great technology to teach you how to build beautiful apps with it. You can find us on Facebook, Twitter, and Medium or learn more about us here. We’d love to connect! And if you are a writer interested in writing for us, then you can do so through these guidelines.

Flutter
Dart
Software Development
Mobile App Development
Programming
Recommended from ReadMedium