FireBase Segment
- Create a Firebase account
- Go to Firebase Console.
- Tap Add Project for the new project.
- Enter the details of your project and tap Create Project.
- Click Continue.
Add your App To Firebase Project
- Tap Android device.
- Tap android > app > build.gradle.
- Copy the applicationId under defaultconfig.
- Then paste the ID on the Android Package name.
- Then tap Register App.
- Now Download google-services.json.
- Copy the Google-services.json file and then paste it into android > app > src.
Add Firebase SDK
- Copy the 1st link and then go to project > build.gradle. Paste classpath ‘com.google.gms:google-services:4.0.1’ under dependencies.
- Now copy the 2nd link and then go to project > app-model > build.gradle. paste apply plugin: ‘com.google.gms.google-services’ at the end of the code
- Then tap next.
- Run your flutter project first and then uninstall it.
- Again run the flutter App.
- Finally, you receive a Flutter Notification window.
- Here you can enter the notification title, text, duration, and tap review.
8. Finally, tap Publish.
Flutter Segment
First Install the package
- After creating a new flutter document move to pubspec.yaml file
- Find Dependencies and then add the package name.
Note: you should add under cupertino_icons: ^0.1.2
firebase_core: firebase_messaging:
3. Tap Package get at the top right corner.
Import the package
- Import the package under the basic package
import 'package:firebase_messaging/firebase_messaging.dart';
2. Given coding is to Configure your notification.
firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) { print('on message $message'); }, onResume: (Map<String, dynamic> message) { print('on resume $message'); }, onLaunch: (Map<String, dynamic> message) { print('on launch $message'); }, );
3. Given coding is to set Notification alert, and sound.
firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings(sound: true, badge: true, alert: true)); firebaseMessaging.getToken().then((token) { print(token); });
4. Tokens are one of the important concepts for firebase notification
firebaseMessaging.getToken().then((token) { update(token); });
Output: