A Flutter sample app for demonstrating how to handle firebase push notifications in the background and foreground.
Notification while the app is running in the background and handle navigation:
Notification while the app is running in the foreground and handle navigation:
The Flutter plugins used in this project are as follows:
Add the following to your pubspec.yaml
file:
cupertino_icons: ^1.0.2
firebase_messaging: ^14.2.5
firebase_analytics: ^8.0.2
flutter_local_notifications: ^13.0.0
firebase_core: ^2.7.0
In order to run this project, you have to follow the steps below:
-
Clone the project:
git clone https://github.com/patoliavishal/flutter-FCM.git
-
Complete Firebase project setup for both Android & iOS platforms by going to the Firebase console.
-
For Android, replace your google-services.json file with an existing file.
android -> app -> google-services.json
-
For running on iOS, you have to do some configurations from Xcode. Follow the guide here.
-
Get Flutter packages:
flutter pub get
-
Run the app:
flutter run
If my example really helpful to you then please don't forgot to press Star
icon.
URL:
https://fcm.googleapis.com/fcm/send
Method:
POST
Header:
"Content-Type": "application/json",
"Authorization": "key=<Server_key>"
Body:
{
"to": "/topics/flutter-notification",
"notification": {
"body": "Test Push Notification",
"title": "Push Notification",
"redirect": "product"
},
"data": {
"title": "Push Notification",
"message": "Test Push Notification",
"redirect": "product"
}
}
Refer http-server-ref for more help.
Copyright (c) 2023 Vishal Patolia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create New Pull Request