使用 firebase 和 Awesome_notifications 在 flutter 中显示推送通知

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

我想在来自 firebase 时显示一条通知,就像这个一样,使用 Awesome_notification

desired result

我的包裹:

awesome_notifications: ^0.9.3+1
awesome_notifications_fcm: ^0.9.2

目前我只了解如何进行本地通知。 我了解听众

 await AwesomeNotifications().setListeners(
      onActionReceivedMethod: onActionReceivedMethod,
      onNotificationCreatedMethod: onNotificationCreatedMethod,
      onNotificationDisplayedMethod: onNotificationDisplayedMethod,
      onDismissActionReceivedMethod: onDismissActionReceivedMethod,
    );

但我真的不明白如何在不进行无限通知循环的情况下实现我的任务( 我将非常感谢您的想法!

flutter firebase firebase-cloud-messaging awesome-notifications
1个回答
0
投票

尝试阅读以下材料

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  AwesomeNotifications().createNotification(
    content: NotificationContent(
      id: 100,//<-- pass/createUniqueId(),
      channelKey: 'basic_channel',
      title: message.notification.title,
      body: message.notification.body,
      bigPicture: 'https://imagePath/eee....png',
      largeIcon: 'https://imagePath/larg....png',
      notificationLayout: NotificationLayout.BigPicture,
    ),//

    actionButtons: [ //<--if needed
      NotificationActionButton(key: 'REDIRECT', label: 'Redirect'),
      NotificationActionButton(
          key: 'REPLY',
          label: 'Reply Message',
          requireInputText: true,
          actionType: ActionType.SilentAction
      ),
      NotificationActionButton(
          key: 'DISMISS',
          label: 'Dismiss',
          actionType: ActionType.DismissAction,
          isDangerousOption: true)
    ]);
});//

更多内容请阅读awesome_notifications_fcm/example

© www.soinside.com 2019 - 2024. All rights reserved.