-
Notifications
You must be signed in to change notification settings - Fork 815
feat: Implemented the light and dark mode #2706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: flutter
Are you sure you want to change the base?
feat: Implemented the light and dark mode #2706
Conversation
Reviewer's GuideThis PR adds comprehensive light/dark mode support by introducing a ThemeProvider (with persistence via shared_preferences), defining static theme data in AppTheme, integrating theme switching into MaterialApp, providing a manual theme‐selection UI in SettingsScreen, and updating existing UI components to use ThemeData’s color scheme instead of hard‐coded colors. Sequence Diagram for Manual Theme SelectionsequenceDiagram
actor User
participant SettingsScreen
participant ThemeSelectionDialog
participant ThemeProvider
participant SharedPreferences
User->>SettingsScreen: Taps 'Theme' option
SettingsScreen->>ThemeSelectionDialog: _showThemeSelectionDialog()
activate ThemeSelectionDialog
ThemeSelectionDialog-->>User: Displays theme options (System, Light, Dark)
User->>ThemeSelectionDialog: Selects a theme (e.g., Dark)
ThemeSelectionDialog->>ThemeProvider: setThemeMode(ThemeMode.dark)
activate ThemeProvider
ThemeProvider->>ThemeProvider: Updates _themeMode
ThemeProvider->>ThemeProvider: notifyListeners()
ThemeProvider->>ThemeProvider: _saveThemeMode()
ThemeProvider->>SharedPreferences: Saves themeMode.index for key '_themeKey'
activate SharedPreferences
SharedPreferences-->>ThemeProvider: Confirms save
deactivate SharedPreferences
ThemeProvider-->>ThemeSelectionDialog: Returns
deactivate ThemeProvider
ThemeSelectionDialog->>SettingsScreen: Closes dialog (Navigator.pop())
deactivate ThemeSelectionDialog
Class Diagram for Core Theme System (ThemeProvider and AppTheme)classDiagram
class ChangeNotifier {
<<Flutter Framework>>
#notifyListeners()
}
class ThemeProvider {
<<Provider>>
-String _themeKey
-ThemeMode _themeMode
+ThemeProvider()
+ThemeMode get themeMode
+void setThemeMode(ThemeMode themeMode)
+Future~void~ loadThemeMode()
-Future~void~ _saveThemeMode()
+String getThemeDisplayName()
}
ChangeNotifier <|-- ThemeProvider
class AppTheme {
<<Utility>>
+static ThemeData lightTheme
+static ThemeData darkTheme
}
class ThemeMode {
<<Enum>>
System
Light
Dark
}
ThemeProvider ..> ThemeMode : uses
ThemeProvider ..> SharedPreferences : uses for persistence
class SharedPreferences {
<<External Library>>
+Future~bool~ setInt(String key, int value)
+int? getInt(String key)
+Future~void~ getInstance()
}
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Build successful. APKs to test: https://github.com/fossasia/pslab-android/actions/runs/15254018007/artifacts/3197219709 |
import 'constants.dart'; | ||
|
||
void main() { | ||
Future<void> main() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is main()
async? Shouldn't be.
await _saveThemeMode(); | ||
} | ||
|
||
Future<void> loadThemeMode() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving theme in SharedPreferences
isn't required. Let's implement a simpler model for this. If a user has to always use dark theme for the app, the System
option is available.
Fixes #2705
Changes
Added theme data for light and dark modes.
Implemented automatic theme switching based on device settings.
Added a theme selection option in the app settings to manually switch themes.
Updated UI components and screens to support theme changes.
Screenshots / Recordings
Screen.Recording.2025-05-26.175243.mp4
Checklist:
strings.xml
,dimens.xml
andcolors.xml
without hard coding any value.strings.xml
,dimens.xml
orcolors.xml
.Summary by Sourcery
Implement light and dark mode support with system and manual theme selection, persist user preference, and update UI to use theme colors.
New Features:
Enhancements:
Build:
Chores: