[英]Flutter Awesome Notification couldn't bind a method to action button
我正在開發一個需要回答通知的應用程序。 我可以在收到通知時顯示按鈕。 但是,我無法將任何方法綁定到它。 這是我的代碼:
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Simple Notification',
body: 'Simple body'),
actionButtons: [
NotificationActionButton(
label: 'TEST',
enabled: true,
buttonType: ActionButtonType.Default,
key: 'test',
)
]);
print("Background message service");
}
謝謝你的幫助!
您應該創建一個事件 stream 並收聽這樣的事件:
AwesomeNotifications().actionStream.listen((event) {
print('event received!');
print(event.toMap().toString());
// do something based on event...
});
從新版本更新任何人。 您可以按照文檔處理通知點擊和其他各種操作。 這就是我所做的。 文檔
class NotificationController {
/// Use this method to detect when the user taps on a notification or action button
@pragma("vm:entry-point")
static Future<void> onActionReceivedMethod(ReceivedAction receivedAction) async {
// Your code goes here
/// Handles regular notification taps.
if(receivedAction.actionType == ActionType.Default){
if(receivedAction.id == 17897583){
// do something...
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.