【发布时间】:2021-01-28 13:05:42
【问题描述】:
我有 2 种 Firestore 触发器来向用户发送通知 - 1 是在新用户创建请求表单时触发,2 是在用户收到另一个用户的消息时触发。对于每种情况,我想在点击通知时将用户重定向到 2 个不同的页面。
notifications 页面用于第一种情况,chatRoom 页面用于第二种情况。这是我的代码,我不知道如何根据 2 个不同的情况重定向到 2 个不同的页面。请给我一些建议。
@override
void initState() {
super.initState();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
var data = message['data'];
if (data['screen'].toString() == 'ChatClass') {
Navigator.push(... (context) => ChatRoom()));
} else {
Navigator.push(... (context) => Notifications()));
}
}, onLaunch: (Map<String, dynamic> message) async {
var data = message['data'];
if (data['screen'].toString() == 'ChatClass') {
Navigator.push(... (context) => ChatRoom()));
} else {
Navigator.push(... (context) => Notifications()));
}
}, onResume: (Map<String, dynamic> message) async {
var data = message['data'];
if (data['screen'].toString() == 'ChatClass') {
Navigator.push(... (context) => ChatRoom()));
} else {
Navigator.push(...(context) => Notifications()));
}
});
}
这是我的 AndroidManifest 文件;
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myappName">
//
<application
android:name=".Application"
android:label="myapp"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
//
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
//
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
//
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
【问题讨论】:
-
您必须简单地将数据从您的 fireabse 控制台传递到 json 格式的通知,在此基础上您可以浏览页面
-
@ShubhamNarkhede 感谢 Shubham。我不明白“将数据从firebase控制台传递到json格式的通知”是什么意思。请给我举个例子好吗?
-
请检查我的回答
标签: flutter push-notification firebase-cloud-messaging