firebase - Is there any way to implement push notifications with action buttons in flutter? Using firebase_messaging
问题描述
I am looking for this functionality:
I am looking for pointers. Could not find any tutorials or packages providing this kind of functionality.
Thank you for your help!
解决方案
有一个名为awesome_notifications的包,您可以将其用于此目的。要添加自定义操作按钮,您可以这样做:
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 0,
channelKey: 'basic_channel',
title: 'Simple title',
body: 'Simple body ',
),
actionButtons: [
NotificationActionButton(
key: 'accept',
label: 'Accept',
),
NotificationActionButton(
key: 'cancel',
label: 'Cancel',
),
],
);
对于基于操作的操作,您必须收听此流:
AwesomeNotifications().actionStream.listen((event) {
if (event.buttonKeyInput == 'cancel') //...
else // ...
});
您可以在应用程序启动并运行时使用此库,但当应用程序终止时您实际上无法使用它,您最好使用 FCM 通知,然后打开应用程序,然后根据通知类型采取措施。
推荐阅读
- java - 2 个配置文件,2 个方法实现,1 个通过 Thymeleaf 调用 html 文件。如何?
- c# - vstest with TFS build: System.Runtime.Remoting.RemotingException: 'Object '/XXX.rem' has been disconnected or not exist at server
- jvm - Google caliper -XX:CICompilerCount=2 vmOption 不适用
- javascript - Youtube 视频未播放:解析标头 X-XSS-Protection 时出错
- node.js - 触发函数内的所有变量获取值后的实时数据库触发
- apache-spark - .withColumn 不提供数据框的原始列,而只提供新添加的列
- angular - submitEl.triggerEventHandler 不是 Angular 5 中的函数
- reactjs - 使用反应内联样式切换不同选项卡上的活动状态
- ios - iOS上的Wifi辅助无法正常工作
- angular - ltrim 如何在角度过滤器中工作?