带有操作按钮的 Flutter 本地通知

Flutter local notification with action buttons

我在我的 flutter 项目中尝试了 flutter 本地通知插件,它在简单通知上工作正常,但我需要带有操作按钮的通知功能,请帮助我或建议我实现此功能。

很遗憾,flutter_local_notifications 插件尚不支持操作按钮。有一个 feature request 添加这个。

我不知道有任何其他插件支持这个,所以我认为现在唯一的可能性是创建您自己的自定义插件并使用本机 iOS 代码开发它。

使用awesome_notifications: ^0.0.6+7 包

awesome_notifications 可用于通过操作按钮推送通知。

Explanation:
这可以通过自定义接收到的数据 (Json) 来完成,例如:

{
    "to" : "[YOUR APP TOKEN]",
    "mutable_content" : true,
    "content_available": true,
    "priority": "high",
    "data" : {
        "content": {
            "id": 100,
            "channelKey": "big_picture",
            "title": "Huston!\nThe eagle has landed!",
            "body": "A small step for a man, but a giant leap to Flutter's community!",
            "notificationLayout": "BigPicture",
            "largeIcon": "https://media.fstatic.com/kdNpUx4VBicwDuRBnhBrNmVsaKU=/full-fit-in/290x478/media/artists/avatar/2013/08/neil-i-armstrong_a39978.jpeg",
            "bigPicture": "https://www.dw.com/image/49519617_303.jpg",
            "showWhen": true,
            "autoCancel": true,
            "privacy": "Private"
        },
        "actionButtons": [
            {
                "key": "REPLY",
                "label": "Reply",
                "autoCancel": true,
                "buttonType":  "InputField"
            },
            {
                "key": "ARCHIVE",
                "label": "Archive",
                "autoCancel": true
            }
        ],
        "schedule": {
            "timeZone": "America/New_York",
            "hour": "10",
            "minute": "0",
            "second": "0",
            "millisecond": "0",
            "allowWhileIdle": true,
            "repeat": true
        }
    }
}

并使用该消息数据推送通知,例如:

AwesomeNotifications().createNotificationFromJsonData(yourReceivedMapData);