我想做什么
当用户在通知栏中点击FCM通知时,我希望能导航到特定的屏幕。
我的代码
我已经按照pub.dev上版本6.0.9提到的精确指示进行了操作。
这是我的实现:
_fcm.configure(
onMessage: (Map<String, dynamic> message) async {
print('@onMessage: $message');
},
onResume: (Map<String, dynamic> message) async {
print('@onResume: $message');
Navigator.push(context,
MaterialPageRoute(builder: (context) => NotificationsScreen()));
},
onLaunch: (Map<String, dynamic> message) async {
print('@onLaunch: $message');
Navigator.push(context,
MaterialPageRoute(builder: (context) => NotificationsScreen()));
});
插件版本:firebase_messaging: ^6.0.9
我还添加了以下配置:
app/build.gradle:
implementation 'com.google.firebase:firebase-messaging:20.1.0'
project/build.gradle:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:'1.3.50'"
classpath 'com.google.gms:google-services:4.3.3'
期望输出
当用户在后台中点击通知时,将调用onResume或onLaunch回调并将用户重定向到指定的屏幕。
实际输出
当应用程序在前台时,正确调用onMessage,但不会调用onResume和onLaunch。