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");
}
First of all, let me explain my program. It's a reminder app. If we click remind me button then a notification with an alarm sound will be set else a notification without an alarm sound will be set. There is also an option for altering this decision in future. The problem is that when I set a reminder with an alarm sound notification, the sound is not played. But the sound is played if there is no function for setting an alarm without sound.