Flutter FCM /本地通知:如何访问完整的原始消息?

gab6jxml  于 2023-05-19  发布在  Flutter
关注(0)|答案(1)|浏览(103)

已尝试访问onDidReceiveNotification中的完整消息,但没有candy。notificationResponse中的所有属性都不包含原始完整消息。

/// Sets up Local Notifications and its Listeners
  Future<void> _localNotificationsSetup(
      BuildContext context, CashticUser currentUser) async {
    _flutterLocalNotificationsPlugin.initialize(
        const InitializationSettings(
          android: AndroidInitializationSettings(
              '@drawable/ic_notification'),
          iOS: DarwinInitializationSettings(),
        ), onDidReceiveNotificationResponse:
            (NotificationResponse notificationResponse) async {
      {
        log.d(notificationResponse.notificationResponseType);
        log.d(notificationResponse.actionId);
        log.d(notificationResponse.input);
        log.d(notificationResponse.id);
        log.d(notificationResponse.payload);
moiiocjp

moiiocjp1#

在show方法中提供payload属性:

import 'dart:convert';
// ...
Future<void> showFlutterNotification(RemoteMessage message) async {
  RemoteNotification? notification = message.notification;
  AndroidNotification? android = message.notification?.android;
  if (notification != null && android != null && !kIsWeb) {
flutterNotificationsPlugin.show(
        notification.hashCode,
        notification?.title,
        notification?.body,
        //...
        // message.data contains the payload
        // If your payload is in json, you might also want to encode it since flutter_local_notification accepts strings
        payload: jsonEncode(message.data),
      );
  }
 }
// this log should work now
//  log.d(notificationResponse.payload);

相关问题