feat: add sound and vibration feedback for registration actions
Integrate audioplayers, vibration, and file_picker packages to provide audio/haptic feedback on registration success/failure. Add sound settings UI in SettingsPage for customizing notification sounds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
59
lib/services/sound_service.dart
Normal file
59
lib/services/sound_service.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SoundService {
|
||||
static const _keySuccess = 'sound_success';
|
||||
static const _keyFailure = 'sound_failure';
|
||||
|
||||
final _player = AudioPlayer();
|
||||
|
||||
Future<String?> getSuccessPath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(_keySuccess);
|
||||
}
|
||||
|
||||
Future<String?> getFailurePath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(_keyFailure);
|
||||
}
|
||||
|
||||
Future<void> setSuccessPath(String? path) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (path != null) {
|
||||
await prefs.setString(_keySuccess, path);
|
||||
} else {
|
||||
await prefs.remove(_keySuccess);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setFailurePath(String? path) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (path != null) {
|
||||
await prefs.setString(_keyFailure, path);
|
||||
} else {
|
||||
await prefs.remove(_keyFailure);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> playSuccess() async {
|
||||
final path = await getSuccessPath();
|
||||
if (path != null) {
|
||||
await _player.play(DeviceFileSource(path));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> playFailure() async {
|
||||
final path = await getFailurePath();
|
||||
if (path != null) {
|
||||
await _player.play(DeviceFileSource(path));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> play(String path) async {
|
||||
await _player.play(DeviceFileSource(path));
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _player.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user