Firebase 当应用程序未在前台运行时,如何显示通知数据
我正在使用firebase_消息传递的新版本(8.0.0-dev.8)。当应用程序在前台运行时,我成功地通过以下方式向用户显示了通知详细信息,这要感谢package overlay_的支持:Firebase 当应用程序未在前台运行时,如何显示通知数据,firebase,flutter,notifications,firebase-cloud-messaging,Firebase,Flutter,Notifications,Firebase Cloud Messaging,我正在使用firebase_消息传递的新版本(8.0.0-dev.8)。当应用程序在前台运行时,我成功地通过以下方式向用户显示了通知详细信息,这要感谢package overlay_的支持: FirebaseMessaging.onMessage.listen((RemoteMessage message) { print('Got a message whilst in the foreground!'); showOverlayNotification((context) {
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!');
showOverlayNotification((context) {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 4),
child: SafeArea(
child: ListTile(
title: Text(message.notification.title),
subtitle: Text(message.notification.body),
trailing: IconButton(
icon: Icon(Icons.close),
onPressed: () {
OverlaySupportEntry.of(context).dismiss();
}),
),
),
);
}, duration: Duration(milliseconds: 10000));
});
但是,当应用程序没有运行时,我找不到一种方法来实现相同的结果,因为该函数在主窗口小部件类之外,因此它显然无法访问上下文。我尝试了get软件包,但没有成功。到目前为止,我只有基本代码:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
print("Handling a background message: ${message.data['title']}");
}
Future\u firebaseMessagingBackgroundHandler(RemoteMessage)异步{
//如果要在后台使用其他Firebase服务,例如Firestore,
//确保在使用其他Firebase服务之前调用'initializeApp'。
打印(“处理背景消息:${message.data['title']}”);
}
如果有任何想法,我将不胜感激