refactor: unify error feedback system with FeedbackService and StatusBar widget
- Create FeedbackService as centralized sound/vibration dispatcher - Create reusable StatusBar widget with StatusDotColor enum (blue/orange/green/red/yellow/amber) - Extend SoundService with beep/error/alert sound types and loop playback - Remove top feedback banners from both registration and boxing pages - Route all feedback through bottom status bar per PRD requirements - Add sound and vibration feedback to boxing module (was completely missing) - Handle network errors with yellow status, general errors with red - Enhance duplicate dialog with alert loop sound that stops on close - Add beep/error/alert sound file selectors in settings page Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
83
lib/services/feedback_service.dart
Normal file
83
lib/services/feedback_service.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:vibration/vibration.dart';
|
||||
import 'package:pad_scanner/services/sound_service.dart';
|
||||
|
||||
/// Unified feedback events used across the app.
|
||||
enum FeedbackEvent {
|
||||
scanValid, // Valid barcode scanned → beep + short vibrate
|
||||
scanInvalid, // Invalid barcode → error sound + short vibrate
|
||||
submitSuccess, // Submit succeeded → success sound + long vibrate
|
||||
submitFailure, // Submit failed → failure sound + short vibrate
|
||||
duplicateError, // Duplicate (shelf) → alert loop + continuous vibrate
|
||||
networkError, // Network error → failure sound + short vibrate
|
||||
duplicateBoxNo, // Duplicate box no → failure sound + short vibrate
|
||||
modeSwitch, // Mode toggle → beep only
|
||||
}
|
||||
|
||||
/// Centralized feedback dispatcher.
|
||||
///
|
||||
/// Each page manages its own bottom status bar state; this service handles
|
||||
/// the sound, vibration channels only.
|
||||
class FeedbackService {
|
||||
final SoundService _soundService;
|
||||
|
||||
FeedbackService({SoundService? soundService})
|
||||
: _soundService = soundService ?? SoundService();
|
||||
|
||||
/// Trigger feedback for the given [event].
|
||||
Future<void> trigger(FeedbackEvent event) async {
|
||||
switch (event) {
|
||||
case FeedbackEvent.scanValid:
|
||||
_soundService.playBeep();
|
||||
_vibrateShort();
|
||||
|
||||
case FeedbackEvent.scanInvalid:
|
||||
_soundService.playError();
|
||||
_vibrateShort();
|
||||
|
||||
case FeedbackEvent.submitSuccess:
|
||||
_soundService.playSuccess();
|
||||
_vibrateLong();
|
||||
|
||||
case FeedbackEvent.submitFailure:
|
||||
_soundService.playFailure();
|
||||
_vibrateShort();
|
||||
|
||||
case FeedbackEvent.duplicateError:
|
||||
_soundService.playAlertLoop();
|
||||
_vibratePattern();
|
||||
|
||||
case FeedbackEvent.networkError:
|
||||
_soundService.playFailure();
|
||||
_vibrateShort();
|
||||
|
||||
case FeedbackEvent.duplicateBoxNo:
|
||||
_soundService.playFailure();
|
||||
_vibrateShort();
|
||||
|
||||
case FeedbackEvent.modeSwitch:
|
||||
_soundService.playBeep();
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop any ongoing alert (e.g. when duplicate dialog is closed).
|
||||
Future<void> stopAlert() async {
|
||||
_soundService.stopAlert();
|
||||
}
|
||||
|
||||
void _vibrateShort() {
|
||||
Vibration.vibrate(duration: 100);
|
||||
}
|
||||
|
||||
void _vibrateLong() {
|
||||
Vibration.vibrate(duration: 200);
|
||||
}
|
||||
|
||||
/// Continuous vibration pattern: 3 bursts to signal critical error.
|
||||
void _vibratePattern() {
|
||||
Vibration.vibrate(pattern: [0, 300, 100, 300, 100, 300]);
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _soundService.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user