/flutter-FCM

Flutter-3.0 Firebase Messaging, Foreground, and Background Notifications + Topic Subscription and Handle Redirection

Primary LanguageDartApache License 2.0Apache-2.0

Flutter FCM Push Notification

A Flutter sample app for demonstrating how to handle firebase push notifications in the background and foreground.

Screenshots

Notification while the app is running in the background and handle navigation:

Notification while the app is running in the foreground and handle navigation:

Plugins

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

Usage

In order to run this project, you have to follow the steps below:

  1. Clone the project:

    git clone https://github.com/patoliavishal/flutter-FCM.git
  2. Complete Firebase project setup for both Android & iOS platforms by going to the Firebase console.

  3. For Android, replace your google-services.json file with an existing file.

    android -> app -> google-services.json
  4. For running on iOS, you have to do some configurations from Xcode. Follow the guide here.

  5. Get Flutter packages:

    flutter pub get
  6. Run the app:

    flutter run

If my example really helpful to you then please don't forgot to press Star icon.

Sent Notification Using Postman

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.

License

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.

Contributing to Flutter FCM Push Notification

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create New Pull Request