android only
我尝试了通知服务计划方法与**_flutterLocalNotificationsPlugin.periodicallyShow**,它似乎不工作。
还有如何在Android模拟器中测试(更改设备上的日期和时间是否有效)
通知服务.dart
class NotificationServices {
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
final AndroidInitializationSettings _androidInitializationSettings =
AndroidInitializationSettings('logo1');
void initialiseNotifications() async {
InitializationSettings initializationSettings = InitializationSettings(
android: _androidInitializationSettings,
);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
void scheduleNotifications(String title, String body) async {
int hour = 19;
var ogValue = hour;
int minute = 05;
var time = Time(hour,minute,20);
AndroidNotificationDetails androidNotificationDetails =
const AndroidNotificationDetails(
'channelId',
'channelName',
importance: Importance.max,
priority: Priority.high,
);
NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails,
);
await _flutterLocalNotificationsPlugin.periodicallyShow(
0, 'title', 'body', RepeatInterval.daily, notificationDetails);
}
void stopNotifications() async{
_flutterLocalNotificationsPlugin.cancel(0);
}
}
主省道
NotificationServices notificationServices = NotificationServices();
notificationServices.initialiseNotifications();
notificationServices.scheduleNotifications('Daily Reminder', 'You have a ToDo list to complete');
1条答案
按热度按时间wfveoks01#
我自己解决了这个问题。参考下面的代码谁正在寻找答案