123456789101112131415161718192021222324252627282930313233343536 |
- import 'package:vibration/vibration.dart';
- /// A service to handle notifications and vibration
- class NotificationManager {
- static final NotificationManager _instance = NotificationManager._internal();
-
- factory NotificationManager() {
- return _instance;
- }
-
- NotificationManager._internal();
-
- /// Vibrate the device to notify user of timer completion
- Future<void> notifyTimerCompletion() async {
- await triggerVibration();
- }
-
- /// Trigger vibration pattern
- Future<void> triggerVibration() async {
- if (await Vibration.hasVibrator() ?? false) {
- // Pattern for stronger notification - will repeat 3 times with pauses
- // Vibrate for 500ms, pause for 200ms, repeat
- Vibration.vibrate(
- pattern: [0, 500, 200, 500, 200, 500],
- intensities: [0, 255, 0, 255, 0, 255],
- );
- }
- }
-
- /// Stop vibration
- Future<void> stopVibration() async {
- if (await Vibration.hasVibrator() ?? false) {
- Vibration.cancel();
- }
- }
- }
|