timer_settings.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import 'package:shared_preferences/shared_preferences.dart';
  2. class TimerSettings {
  3. static const String _soundKey = 'timer_sound';
  4. static const String _volumeKey = 'timer_volume';
  5. static const String _vibrateKey = 'timer_vibrate';
  6. static const String _loopKey = 'timer_loop';
  7. String sound;
  8. double volume;
  9. bool vibrate;
  10. bool loop;
  11. TimerSettings({
  12. this.sound = 'Dripping',
  13. this.volume = 0.7,
  14. this.vibrate = true,
  15. this.loop = true,
  16. });
  17. // Save settings to SharedPreferences
  18. Future<void> saveSettings() async {
  19. final prefs = await SharedPreferences.getInstance();
  20. await prefs.setString(_soundKey, sound);
  21. await prefs.setDouble(_volumeKey, volume);
  22. await prefs.setBool(_vibrateKey, vibrate);
  23. await prefs.setBool(_loopKey, loop);
  24. }
  25. // Load settings from SharedPreferences
  26. static Future<TimerSettings> loadSettings() async {
  27. final prefs = await SharedPreferences.getInstance();
  28. return TimerSettings(
  29. sound: prefs.getString(_soundKey) ?? 'Dripping',
  30. volume: prefs.getDouble(_volumeKey) ?? 0.7,
  31. vibrate: prefs.getBool(_vibrateKey) ?? true,
  32. loop: prefs.getBool(_loopKey) ?? true,
  33. );
  34. }
  35. }