对于我即将推出的Fitness-app 用户应该能够选择星期一至星期日之间的多天,选择应该显示通知的小时和星期数。 例如: 我选择星期四和星期五,下午2点和6周。 因此,我应该在周四和周五下午2点看到通知,共6周。
我正在使用'flutter_local_notifications 0.8.3'插件,但是它似乎没有我需要的功能,如果您知道像我上面写的那样显示通知的任何其他方法,请随时告诉我。< / p>
编辑:
我使用for循环设置的计划通知的代码。 但这不是真正的解决方案
Future<void> scheduleNotification(int id,{int, days,int hour, int minute, int second}) async {
var scheduledNotificationDateTime =
DateTime.now().add(Duration(days: days));
var vibrationPattern = Int64List(4);
vibrationPattern[0] = 0;
vibrationPattern[1] = 1000;
vibrationPattern[2] = 5000;
vibrationPattern[3] = 2000;
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your other channel id',
'your other channel name',
'your other channel description',
icon: 'app_icon',
largeIcon: 'app_icon',
largeIconBitmapSource: BitmapSource.Drawable,
vibrationPattern: vibrationPattern,
enableLights: true,
color: const Color.fromARGB(255, 255, 0, 0),
ledColor: const Color.fromARGB(255, 255, 0, 0),
ledOnMs: 1000,
ledOffMs: 500);
var iOSPlatformChannelSpecifics =
IOSNotificationDetails(sound: "slow_spring_board.aiff");
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
id,
'scheduled title',
'scheduled body',
scheduledNotificationDateTime,
platformChannelSpecifics);
}
每周通知的代码
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'show weekly channel id',
'show weekly channel name',
'show weekly description');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
0,
title,
'Weekly notification shown on Monday at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}',
Day.values[value],
time,
platformChannelSpecifics);
}
给定的问题是我不知道在x周后如何停止每周通知
此代码来自插件本身,可让您深入了解该功能的工作原理。 我可以指定日期,时间和重复间隔,但不能指定激活通知的时间。
/// Shows a notification on a daily interval at the specified time
Future<void> showWeeklyAtDayAndTime(int id, String title, String body,
Day day, Time notificationTime, NotificationDetails notificationDetails,
{String payload}) async {
_validateId(id);
var serializedPlatformSpecifics =
_retrievePlatformSpecificNotificationDetails(notificationDetails);
await _channel.invokeMethod('showWeeklyAtDayAndTime', <String, dynamic>{
'id': id,
'title': title,
'body': body,
'calledAt': DateTime.now().millisecondsSinceEpoch,
'repeatInterval': RepeatInterval.Weekly.index,
'repeatTime': notificationTime.toMap(),
'day': day.value,
'platformSpecifics': serializedPlatformSpecifics,
'payload': payload ?? ''
});
}
答案 0 :(得分:1)