Flutter 通知:显示类似 WhatsApp 的通知

问题描述 投票:0回答:1

我正在尝试使用

awesome_notifications
包 (https://pub.dev/packages/awesome_notifications) 在我的 flutter 应用程序中显示通知。下面是我的代码。

await AwesomeNotifications().createNotification(
    content: NotificationContent(
      id: UniqueKey().hashCode,
      groupKey: message.data["senderUid"],
      channelKey: 'basic_channel',
      title: message.data["title"],
      body: message.data["body"],
      summary: message.data["body"], // Anything you want here
      notificationLayout: NotificationLayout.Messaging,
    ),
  );

下面是我的Json数据

"message": {
    "token": recieverFcm,
    "data": {
        "title": senderName,
        "body": message,
        "chatRoomId": chatRoomId,
        "sender_profile_pic": senderProfilePic,
        "senderUid": senderUid,
        "click_action": "OPEN_CHAT_ROOM"
    },
    "android": {
        "priority": "high"
    },
    "apns": {
        "payload": {
            "aps": {
                "category": "OPEN_CHAT_ROOM"
            }
        }
    }
}

这工作正常,我收到如下通知。

在这里,它显示发件人姓名的第一个字母作为图标/个人资料图片。相反,我想显示发件人的真实照片。此个人资料照片已通过 JSON 代码发送。

我该怎么做?

android ios flutter push-notification awesome-notifications
1个回答
0
投票

很晚了,但会回答其他仍在寻找的人。

有一个largeIcon参数,它采用网络图像,用它来显示图像代替默认的圆形头像。

ElevatedButton(
          onPressed: () {
            var groupName = "Group Name";
            var userName = "UserName";
            var message = "Hiii";
            var image = " add network image link"
            AwesomeNotifications().createNotification(
              content: NotificationContent(
                id: UniqueKey().hashCode,
                channelKey: "notifications",
                title: userName,
                body: message,
                summary: groupName,
                payload: {},
                groupKey: groupName,
                largeIcon: image,
                roundedLargeIcon: true,
                notificationLayout: NotificationLayout.MessagingGroup,
              ),
            );
          },
          child: const Text("Send"),
        ),
© www.soinside.com 2019 - 2024. All rights reserved.