飘扬的本地通知未取消
我的通知API代码:
static final _notificationPlugin = FlutterLocalNotificationsPlugin();
static Future<void> showShNotification() async {
tz.initializeTimeZones();
_notificationPlugin.zonedSchedule(
4,
'Some_Title',
'Some_Body',
TZDateTime.from(DateTime.now().add(const Duration(seconds:5)),
getLocation('Asia/Kolkata')),
await _notificationDetails(),payload: 'some_payload',
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true,);
}
static Future _notificationDetails() async {
return NotificationDetails(
// All relevant notification details here
));
}
static Future<void> done(int id) async {
await _notificationPlugin.cancel(id);
}
在TextButton Widget中:
onPressed: () async {
NotificationApi.showShNotification();
await NotificationApi.done(4); // for cancellation
},
带有ID的本地通知(此处为4)未取消。它在5秒后出现。如果我使用了FlutterLocalnotificationplugin()的cancelall()函数,则仅将其取消。是一个错误还是我做错了什么? 请帮助。
编辑:我找到了一个可能的解决方案:
await NotificationApi.showShNotification();
await NotificationApi.done(4);
不是100%确定。但是我猜这是由于插件有点迟钝的事实。
My Notification API Code:
static final _notificationPlugin = FlutterLocalNotificationsPlugin();
static Future<void> showShNotification() async {
tz.initializeTimeZones();
_notificationPlugin.zonedSchedule(
4,
'Some_Title',
'Some_Body',
TZDateTime.from(DateTime.now().add(const Duration(seconds:5)),
getLocation('Asia/Kolkata')),
await _notificationDetails(),payload: 'some_payload',
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true,);
}
static Future _notificationDetails() async {
return NotificationDetails(
// All relevant notification details here
));
}
static Future<void> done(int id) async {
await _notificationPlugin.cancel(id);
}
In TextButton Widget :
onPressed: () async {
NotificationApi.showShNotification();
await NotificationApi.done(4); // for cancellation
},
Local Notification with the given id(here 4) is not cancelled. It appears after 5 seconds. If I used cancelAll() function of FlutterLocalNotificationsPlugin(), only then it is cancelled. Is it a bug or I am doing something wrong?
Kindly help.
EDIT: I found a possible solution to this :
await NotificationApi.showShNotification();
await NotificationApi.done(4);
Not 100% sure. But I am guessing this is due to the fact that the plugin is a bit sluggish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论