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");
}
首先,让我解释一下我的程序。这是一个提醒应用程序。如果我们单击提醒我按钮,则会设置带有警报声音的通知,否则将设置没有警报声音的通知。还有一个选项可以在将来更改此决定。问题是当我设置带有警报声音通知的提醒时,声音没有播放。但是如果没有设置无声闹铃功能,则会播放声音。