Flutter 通知
一个用于 Firebase Cloud Messaging (Firebase 推送通知) 的演示 Flutter 应用
如何在你的项目中实现 Firebase
-
创建 Flutter 项目
-
在 Firebase 控制台中创建项目。
-
通过访问 Firebase 控制台 来完成 Android 和 iOS 平台的 Firebase 项目设置。
-
对于 Android,请用现有的 google-services.json 文件替换你项目中的文件。
android -> app -> google-services.json
-
要在 **iOS** 上运行,你需要从 Xcode 进行一些配置。请在此处 遵循指南。
-
在
pubspec.yaml中添加,
flutter_test: sdk: flutter firebase_messaging: ^14.6.1 flutter_local_notifications: ^14.1.0 firebase_core: ^2.13.0
-
-
在 src/main/manifest 中,
在
<activity/>标签内 (在现有的 intent filter 标签下方)添加,
<activity <intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <application <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="high_importance_channel" /> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher" /> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/notification_color" /> </application> -
在
app/build.gradle中在文件末尾添加 `apply plugin: 'com.google.gms.google-services'`
-
在
android/build.gradle中添加,
classpath 'com.google.gms:google-services:4.3.8' -
尽情享用吧。
如需更多帮助,请在此处 阅读官方文档
