Future scheduleAlarmWithSound(Task task) async {
final exists = await _checkIfAlreadyScheduled(task.id);
if (exists) return;
var scheduleNotificationDateTime =
DateTime.fromMillisecondsSinceEpoch(task.endTime);
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('v1', 'Todo', 'Reminder',
icon: 'icon',
importance: Importance.max,
priority: Priority.high,
largeIcon: DrawableResourceAndroidBitmap('icon'),
sound: RawResourceAndroidNotificationSound('annoyingalarm'),
playSound: true,
showWhen: true);
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
task.id,
task.task,
'Time\'s up!\n Did you completed the task?\nIf not better luck next time.',
scheduleNotificationDateTime,
platformChannelSpecifics);
print("Alarm scheduled with sound");
}
Future scheduleAlarmWithoutSound(Task task) async {
final exists = await _checkIfAlreadyScheduled(task.id);
if (exists) return;
var scheduleNotificationDateTime =
DateTime.fromMillisecondsSinceEpoch(task.endTime);
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('v1', 'Todo', 'Reminder',
icon: 'icon',
importance: Importance.max,
priority: Priority.high,
largeIcon: DrawableResourceAndroidBitmap('icon'),
playSound: false,
showWhen: true);
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
task.id,
task.task,
'Time\'s up! Did you completed the task?',
scheduleNotificationDateTime,
platformChannelSpecifics);
print("Alarm scheduled without sound");
}
首先,让我解释一下我的程序。这是一个提醒应用程序。如果我们单击提醒我按钮,则会设置带有警报声的通知,否则将设置没有警报声的通知。将来也可以选择更改此决定。问题是,当我设置带有闹钟声音通知的提醒时,没有播放声音。但是如果没有设置无声闹钟功能,则播放声音。