【问题标题】:How to unschedule previously scheduled local notifications after some time?如何在一段时间后取消安排以前安排的本地通知?
【发布时间】:2020-06-16 10:55:57
【问题描述】:

我正在使用flutter_local_notifications 库来安排每 1 小时一次的本地通知。它按预期工作,但现在,我需要一种方法来启动/停止通知计划(例如,按下按钮)。

我在文档中找不到有关取消预定通知请求的任何内容。

【问题讨论】:

    标签: flutter dart localnotification


    【解决方案1】:

    取消/删除通知

    // cancel the notification with id value of zero
    await flutterLocalNotificationsPlugin.cancel(0);
    // 0 is your notification id
    

    取消/删除所有通知

    await flutterLocalNotificationsPlugin.cancelAll();
    

    是的,这可以取消当前和未来的通知。只需确保正确的通知 ID。

    【讨论】:

      【解决方案2】:

      docs 中,它在取消/删除通知中给出

      await flutterLocalNotificationsPlugin.cancel(0);

      【讨论】:

      • 感谢您的回复,但那是取消id值为0的通知
      • ok,需要根据其他参数取消吗?
      • 并非所有 .cancel() 都会从通知托盘中删除通知。我希望能够停止以后每隔一小时弹出的通知
      • 执行await flutterLocalNotificationsPlugin.cancelAll();后通知是否没有停止?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2012-11-26
      相关资源
      最近更新 更多