Settings
Comprehensive guide to the Settings system in the Flutter application.
The Settings system in the Flutter application is designed to be highly customizable, modular, and user-friendly. It leverages Riverpod for state management and SharedPreferences for persistence, providing a seamless experience for managing user preferences.
Architecture Overview
The settings system is built on a modular architecture where each category has its own dedicated page and provider.
- State Management: Uses
StateNotifierandRiverpodfor reactive updates across the app. - Persistence: Preferences are saved locally using
SharedPreferences. - UI Components: Built using custom design tokens (
DesignTokens) for consistent styling across light and dark modes. - Localization: Fully integrated with standard Flutter localization (
AppLocalizations).
Settings Categories
1. General Settings
Managed by lib/pages/settings/general/page.dart and UserPreferencesProvider.
| Feature | Description |
|---|---|
| Language & Region | Users can change the app language and region settings. |
| Time Zone | Automatically or manually set the application time zone. |
| Privacy | Toggle usage data sharing and personalized experience recommendations. |
| Data Management | Tools for clearing application cache and managing download preferences. |
2. Appearance Settings
Managed by lib/pages/settings/appearance/page.dart and ThemeProvider.
This section is the most visually rich part of the settings, offering:
- Theme Mode: Switch between Light, Dark, or System-defined modes.
- Design Themes: Choose from predefined themes such as Modern, Retro, or Cozy (defined in
AppTheme). - Accent Colors: Personalize the primary application colors (Emerald, Blue, Indigo, etc.).
- Display Options:
- Text Size: Slider-based control for system-wide text scaling.
- Bold Text: Toggle for high-contrast/bold typography.
- Reduce Motion: Option to limit animations for accessibility.
- Compact Mode: Switch between comfortable and information-dense layouts.
3. Notification Settings
Managed by lib/pages/settings/notifications/page.dart and NotificationSettingsProvider.
| Group | Options |
|---|---|
| Push Notifications | A master toggle to enable or disable all push alerts. |
| Marketing & Tips | Optional alerts for promotions, health tips, and app updates. |
| Sound & Feedback | Customize notification sounds and vibration patterns. |
4. Security Settings
Managed by lib/pages/settings/security/page.dart and SecurityProvider.
Comprehensive security management including:
- Authentication:
- Change Password: Dedicated flow for updating account credentials.
- Biometric Login: Integration with Face ID / Fingerprint via local auth.
- Two-Factor Auth (2FA): Toggle for enhanced account protection.
- Session Management:
- View all active devices and login locations.
- Ability to revoke specific sessions or "Sign out from all devices."
- Login History: A detailed log of successful and failed login attempts.
- Danger Zone: A secure process for permanent account deletion.
Technical Implementation
Accessing Settings State
To access or observe settings in your widgets, use the dedicated providers:
// Example: Accessing Theme Mode
final themeMode = ref.watch(themeModeProvider);
// Example: Accessing User Preferences
final userPrefs = ref.watch(userPreferencesProvider);Modifying Settings
Always use the provided notifier methods to ensure state is updated and persisted correctly:
// Updating Theme Mode
ref.read(themeModeProvider.notifier).setMode(AppThemeMode.dark);
// Updating Privacy Preference
ref.read(userPreferencesProvider.notifier).setShareUsageData(true);Help Center
While accessible via the Settings menu, the Help Center is treated as a separate feature set. It includes:
- Frequently Asked Questions (FAQ)
- Contact Support
- Feedback Submission
- Live Chat Integration
For more details, refer to the Help Center Documentation.
Best Practices for Developers
- Always Persist: Ensure any new setting is added to
SharedPreferencesin the notifier's update method. - Reactive UI: Use
ref.watchto ensure the UI updates instantly when a setting changes. - Localization: Never hardcode strings; always add new labels to the
app_en.arb(and other translation) files. - Design Tokens: Use
ref.watch(designTokensProvider)for all styling to respect theme and accessibility settings (like Bold Text).