Flutter Integrate OneSignal Push Notification

Nhan Cao
2 min readMar 26, 2020

— -

First step: Get iOS cert (mobileprovision + .p12)

NOTE: iOS emulator can NOT get push notification

Config on website

  • Login to https://console.firebase.google.com/
  • Create a new project
  • At Project Overview -> Go to Project settings -> Cloud Messaging
  • Copy Server key and Sender ID which keys use to register on OneSignal
  • Create new OneSignal account and go to https://app.onesignal.com/
  • Select Settings ->
  • Select “Google Android” -> Fill “Firebase Server Key” and “Firebase Sender Key” which get from the previous step on Firebase console -> Next to save and Leave Setup
  • Select “Apple iOS” -> Select “Upload optional sandbox certificate” -> Upload “.p12” and Next to save and Leave Setup
  • If all correct -> you will see the “ACTIVE” label

Config on Android app

  • Goto https://console.firebase.google.com/
  • Select Project Overview
  • Press “+ Add app”
  • Select Android => Fill “Android package name” -> Register app -> Download “google-services.json” and place that file to “android/app/google-services.json”
  • Goto Flutter project
  • Edit “android/app/build.gradle” -> Add below snip code at top (line 1)
buildscript {
repositories {
// ...
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
// ...
// OneSignal-Gradle-Plugin
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
  • Add plugin
apply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"apply plugin: 'com.google.gms.google-services'
  • Edit “android/build.gradle”
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {…