我可以在应用启动时发出本地通知,但不能在特定时间发出预定通知,以下代码是我每次打开应用程序时都会触发的本地通知
local_notification.dart
Code
main.dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:meta/meta.dart';
NotificationDetails get _noSound {
final androidChannelSpecifics = AndroidNotificationDetails(
'silent channel id',
'silent channel name',
'silent channel description',
playSound: false,
);
final iOSChannelSpecifics = IOSNotificationDetails(presentSound: false);
return NotificationDetails(androidChannelSpecifics, iOSChannelSpecifics);
}
Future showSilentNotification(
FlutterLocalNotificationsPlugin notifications, {
@required String title,
@required String body,
int id = 0,
}) =>
_showNotification(notifications,
title: title, body: body, id: id, type: _noSound);
NotificationDetails get _ongoing {
final androidChannelSpecifics = AndroidNotificationDetails(
'your channel id',
'your channel name',
'your channel description',
importance: Importance.Max,
priority: Priority.High,
ongoing: true,
autoCancel: false,
);
final iOSChannelSpecifics = IOSNotificationDetails();
return NotificationDetails(androidChannelSpecifics, iOSChannelSpecifics);
}
Future showOngoingNotification(
FlutterLocalNotificationsPlugin notifications, {
@required String title,
@required String body,
int id = 0,
}) =>
_showNotification(notifications,
title: title, body: body, id: id, type: _ongoing);
Future _showNotification(
FlutterLocalNotificationsPlugin notifications, {
@required String title,
@required String body,
@required NotificationDetails type,
int id = 0,
}) =>
notifications.show(id, title, body, type);
我的问题是,即使关闭了应用程序,如何在特定时间(例如,晚上10:00)发出预定的通知? 我尝试了很多方法,即使调度通知根本不起作用,也无法达到我想要的效果
答案 0 :(得分:0)
notifications.schedule(...)
而不是notifications.show(...)