Learn how to send a push notification to Android, IOS, and Flutter Web on new document creation on Firestore.
📕 Things covered in this tutorial:
Make sure you have flutter installed if not visit flutter.dev
So let’s get started coding,
Step 1: Create a flutter project, I am going to do it with Android studio you can user terminal/cmd or VS code there will be no difference.
to create project in android studio click +Start a new flutter project > select flutter application > provide project name and click next.
Step 2: We will start by getting rid of all the comments in the main.dart and getting rid of MyHomePage() stateful widget
this helps in getting the code more clean to work with.
Step 3: Create a folder/package inside the lib
we will create all the screens in this folder so I am going to name this views. then create home.dart.
just add a stateful widget called Home can call it from MyApp.
Step 4: Create a new Firebase Project
once the project is created.
Step 5: Writing cloud function code we can write it in Javascript and Typescript, don’t worry if you don’t have experience with these
we will use javascript.
Step 6: Add firebase to your Android, IOS or Web app
Android
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
...
}
}
apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'
dependencies {
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:17.5.0'
// add SDKs for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}
Step 7: Add cloud firestore package & firebase_messaging from pub.dev
Multi Index : If you find this anywhere in the error then Modify your build.gradle
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
#flutter #firebase #mobile-apps #web-development #developer