import 'package:shared_preferences/shared_preferences.dart'; class TimerSettings { static const String _soundKey = 'timer_sound'; static const String _volumeKey = 'timer_volume'; static const String _vibrateKey = 'timer_vibrate'; static const String _loopKey = 'timer_loop'; String sound; double volume; bool vibrate; // 是否震动 bool loop; // 是否循环 TimerSettings({ this.sound = 'Dripping', this.volume = 0.7, this.vibrate = true, this.loop = true, }); // Save settings to SharedPreferences Future saveSettings() async { final prefs = await SharedPreferences.getInstance(); await prefs.setString(_soundKey, sound); await prefs.setDouble(_volumeKey, volume); await prefs.setBool(_vibrateKey, vibrate); await prefs.setBool(_loopKey, loop); } // Load settings from SharedPreferences static Future loadSettings() async { final prefs = await SharedPreferences.getInstance(); return TimerSettings( sound: prefs.getString(_soundKey) ?? 'Dripping', volume: prefs.getDouble(_volumeKey) ?? 0.7, vibrate: prefs.getBool(_vibrateKey) ?? true, loop: prefs.getBool(_loopKey) ?? true, ); } }