how to implement push notification in flutter

后端 未结 3 821
猫巷女王i
猫巷女王i 2020-12-29 03:44

Hi I am trying to implement push notification in flutter how to display as notification can any one help,I am able to listen as I am getting notification but I am not able t

相关标签:
3条回答
  • 2020-12-29 04:31

    1. Add Dependency

    For sending push notifications we use a plugin called firebase_messaging…

    https://pub.dev/packages/firebase_messaging

    Open your pubspec.yaml file and add this dependency

    dependencies: firebase_messaging: ^6.0.9


    2. Firebase Account

    Make sure you have a firebase account before proceeding.
    In the next step, you should be able to download the google-services.json file.

    After downloading the file, make sure to copy it inside the app/ folder of your Android project.


    3. Android Manifest

    ADD

    <intent-filter>
      <action android:name="FLUTTER_NOTIFICATION_CLICK" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    

    Add these lines to [project]/android/build.gradle

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath 'com.google.gms:google-services:4.3.3'
    }
    



    Add these lines to [project]/android/app/build.gradle

     dependencies {
       implementation fileTree(dir: "libs", include: ["*.jar"])
       implementation 'androidx.appcompat:appcompat:1.1.0'
       implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
       implementation 'com.google.firebase:firebase-messaging:20.2.3'
       implementation 'com.google.firebase:firebase-analytics:17.4.4'
    
       // Add the SDK for Firebase Cloud Messaging
       testImplementation 'junit:junit:4.12'
       androidTestImplementation 'androidx.test.ext:junit:1.1.1'
       androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    
     }
    
    
     apply plugin: 'com.google.gms.google-services'
    

    DONE

    0 讨论(0)
  • 2020-12-29 04:37

    If you're trying to put messages on the lock screen, make sure you're sending a "notification" message type, rather than a "data" message that will be delivered to the running app. You can learn more about the different types of Firebase messages in the Firebase developer guide.

    0 讨论(0)
  • 2020-12-29 04:42

    Push notifications in Flutter can be particularly difficult because you have to do twice the work to get them working with Android & iOS' particular implementations (both of which are, of course, quite different).

    I've been building the OneSignal SDK for flutter. It will be ready within a few days. We work pretty hard to simplify push notifications as much as possible, and it's easy to use our SDK in a GDPR compliant way.

    The repo is here (https://github.com/OneSignal/OneSignal-Flutter-SDK), it's open source and we welcome contributions from anyone. It acts as a wrapper on top of the native Android & iOS OneSignal SDK's.

    0 讨论(0)
提交回复
热议问题