notification_manager.dart 994 B

123456789101112131415161718192021222324252627282930313233343536
  1. import 'package:vibration/vibration.dart';
  2. /// A service to handle notifications and vibration
  3. class NotificationManager {
  4. static final NotificationManager _instance = NotificationManager._internal();
  5. factory NotificationManager() {
  6. return _instance;
  7. }
  8. NotificationManager._internal();
  9. /// Vibrate the device to notify user of timer completion
  10. Future<void> notifyTimerCompletion() async {
  11. await triggerVibration();
  12. }
  13. /// Trigger vibration pattern
  14. Future<void> triggerVibration() async {
  15. if (await Vibration.hasVibrator() ?? false) {
  16. // Pattern for stronger notification - will repeat 3 times with pauses
  17. // Vibrate for 500ms, pause for 200ms, repeat
  18. Vibration.vibrate(
  19. pattern: [0, 500, 200, 500, 200, 500],
  20. intensities: [0, 255, 0, 255, 0, 255],
  21. );
  22. }
  23. }
  24. /// Stop vibration
  25. Future<void> stopVibration() async {
  26. if (await Vibration.hasVibrator() ?? false) {
  27. Vibration.cancel();
  28. }
  29. }
  30. }