如何在一段时间后取消先前安排的本地通知?

rya*_*rya 8 localnotification dart flutter

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

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

Aun*_*Man 14

取消/删除通知

// cancel the notification with id value of zero
await flutterLocalNotificationsPlugin.cancel(0);
// 0 is your notification id
Run Code Online (Sandbox Code Playgroud)

取消/删除所有通知

await flutterLocalNotificationsPlugin.cancelAll();
Run Code Online (Sandbox Code Playgroud)

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


dev*_*tgs 5

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

await flutterLocalNotificationsPlugin.cancel(0);