35 lines
947 B
Dart
35 lines
947 B
Dart
import 'dart:io';
|
|
import 'package:alarm/alarm.dart';
|
|
|
|
class AlarmServices {
|
|
Future<void> showAlarm(String title, String body) async {
|
|
final DateTime now = DateTime.now();
|
|
final AlarmSettings alarmSettings = AlarmSettings(
|
|
id: 42,
|
|
dateTime: now,
|
|
assetAudioPath: 'assets/sounds/warning_alarm.mp3',
|
|
loopAudio: true,
|
|
vibrate: true,
|
|
warningNotificationOnKill: Platform.isIOS,
|
|
androidFullScreenIntent: true,
|
|
allowAlarmOverlap: true,
|
|
volumeSettings: VolumeSettings.fade(
|
|
volume: 1.0,
|
|
fadeDuration: const Duration(seconds: 3),
|
|
volumeEnforced: true,
|
|
),
|
|
notificationSettings: NotificationSettings(
|
|
title: title,
|
|
body: body,
|
|
stopButton: 'Dừng cảnh báo',
|
|
icon: 'ic_launcher',
|
|
),
|
|
);
|
|
await Alarm.set(alarmSettings: alarmSettings);
|
|
}
|
|
|
|
void cancelAlarm({int id = 42}) async {
|
|
await Alarm.stop(id);
|
|
}
|
|
}
|