Prompt file imported from Clark605/qrty (
.github/prompts/plan-settingsScreen.prompt.md). Copyright stays with the author.
Plan: Settings Screen Implementation
Build a Settings screen with two sections (Settings & Support) featuring toggle switches for Vibrate/Beep and navigation items for Rate Us/Privacy Policy/Share, matching the exact UI design with clean architecture and state persistence.
Commits Structure
Commit 1: Add dependencies and setup services
- Add packages:
shared_preferences,vibration,audioplayers - Create
SettingsServicewith SharedPreferences - Create
FeedbackServicewith vibration and sound - Add beep sound asset
Commit 2: Create settings state management
- Create
SettingsCubitandSettingsState - Implement settings methods (load, toggle)
Commit 3: Build settings UI components
- Create
SettingsSectionHeaderwidget - Create
SettingsToggleItemwidget - Create
SettingsNavigationItemwidget
Commit 4: Implement settings screen
- Create
SettingsScreenwith UI layout - Wire up cubit and toggle switches
- Add navigation handlers
Commit 5: Integrate settings with router
- Add settings route to
AppRouter - Update app section navigation
Commit 6: Wire feedback to scan QR feature
- Update
ScanQrCubitto useFeedbackService - Test feedback with different settings
Steps
-
Add Dependencies & Setup State Persistence
- Add
shared_preferences: ^2.3.4topubspec.yamldependencies - Add
vibration: ^2.0.0topubspec.yamlfor vibration feedback - Add
audioplayers: ^6.1.0topubspec.yamlfor beep sound - Create
lib/core/services/settings_service.dartto handle SharedPreferences operations (get/set vibrate and beep preferences) - Create
lib/core/services/feedback_service.dartto handle vibration and sound playback using settings from SettingsService - Use singleton pattern for both services to maintain single instance across app
- Add beep sound file (beep.mp3) to
assets/sounds/directory and register inpubspec.yaml
- Add
-
Create Settings State Management
- Create
lib/feature/settings/cubit/settings_cubit.dartwithSettingsCubitclass - Create
lib/feature/settings/cubit/settings_state.dartaspart ofcubit file withisVibrateEnabledandisBeepEnabledboolean properties - Implement methods:
loadSettings(),toggleVibrate(),toggleBeep()that interact with SettingsService - Use Equatable for state comparison following existing cubit patterns in
scan_qr_cubit.dartandqr_view_cubit.dart
- Create
-
Build Settings UI Components
- Create
lib/feature/settings/widgets/settings_section_header.dartwidget for "Settings" and "Support" yellow text headers withcontext.sp(20)font size - Create
lib/feature/settings/widgets/settings_toggle_item.dartwith icon (SVG), title, subtitle, and yellow Switch widget usingAppAssets.vibrate/AppAssets.notificationicons - Create
lib/feature/settings/widgets/settings_navigation_item.dartwith icon, title, subtitle, and tap handler for Rate Us/Privacy Policy/Share items - Style with
AppColors.secondarybackground,AppColors.whitetext,AppColors.primaryfor active states, using responsive sizing (context.wp(),context.hp(),context.sp())
- Create
-
Implement Settings Screen
- Build
lib/feature/settings/view/settings_screen.dartwithAppBackgroundwrapper andBlocBuilder<SettingsCubit, SettingsState> - Add AppBar with "Settings" title using
LocaleKeys.settings.tr()andAppColors.white - Create ScrollView with two sections: Settings section (Vibrate toggle, Beep toggle with yellow dividers) and Support section (Rate Us, Privacy Policy, Share with yellow dividers)
- Wire up toggle switches to
cubit.toggleVibrate()andcubit.toggleBeep()methods - Implement navigation handlers: Rate Us , Privacy Policy , Share (placeholders for now)
- Build
-
Integrate with Router & App
- Add settings route case in
lib/core/routes/app_router.dartgenerateRoute()method usingAnimationRoutewithBlocProviderwrappingSettingsScreen - Update
lib/feature/app_section/view/app_section.dartif settings button needs to be added to main navigation - Test navigation to settings screen from app section using
context.pushNamed(Routes.settings)
- Add settings route case in
-
Wire Feedback to Scan QR Feature
- Update
lib/feature/scan_qr/cubit/scan_qr_cubit.dart:- Import
FeedbackService - In
onBarcodeDetected()method, after detecting a valid barcode and before emitting state:await FeedbackService.instance.playFeedback(); - This will check SettingsService for vibrate/beep preferences and trigger:
- Vibration if
isVibrateEnabledis true (usingVibration.vibrate(duration: 200)) - Beep sound if
isBeepEnabledis true (usingAudioPlayerto play beep.mp3)
- Vibration if
- Import
- FeedbackService logic:
Future<void> playFeedback() async { final settings = await SettingsService.instance.getSettings(); if (settings.isVibrateEnabled) { await Vibration.vibrate(duration: 200); } if (settings.isBeepEnabled) { await _audioPlayer.play(AssetSource('sounds/beep.mp3')); } } - This ensures feedback happens immediately when QR is detected, respecting user preferences
- Test with all combinations: vibrate only, beep only, both enabled, both disabled
- Update
Further Considerations
- Beep Sound Asset - Need to provide or generate a short beep sound file (beep.mp3 or beep.wav). Should be a quick, pleasant sound (300-500ms duration).