-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add toggle in settings page for Appearance #621
Add toggle in settings page for Appearance #621
Conversation
AlaaElattar
commented
Oct 2, 2024
•
edited
Loading
edited
- Added toggle to switch between light and dark modes from settings page.
- If app is installed for the first time, the theme will be the systems's theme.
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.
app/lib/widgets/theme_provider.dart
Outdated
var brightness = | ||
SchedulerBinding.instance.platformDispatcher.platformBrightness; | ||
_themeMode = brightness == Brightness.dark | ||
? ThemeMode.dark | ||
: ThemeMode.light; |
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.
Checking the brightness here will make the app start with one mode and not reflect when changing the system mode.
I prefer to return ThemeMode.system
here and check the brightness before rendering the switch if the mode is the system.
bool isSystemDarkMode = false; | ||
if (themeProvider.themeMode == ThemeMode.system){ | ||
var brightness = | ||
SchedulerBinding.instance.platformDispatcher.platformBrightness; | ||
isSystemDarkMode = brightness == Brightness.dark; | ||
} | ||
bool isDarkMode = themeProvider.themeMode == ThemeMode.dark || | ||
(themeProvider.themeMode == ThemeMode.system && isSystemDarkMode); |
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.
bool isSystemDarkMode = false; | |
if (themeProvider.themeMode == ThemeMode.system){ | |
var brightness = | |
SchedulerBinding.instance.platformDispatcher.platformBrightness; | |
isSystemDarkMode = brightness == Brightness.dark; | |
} | |
bool isDarkMode = themeProvider.themeMode == ThemeMode.dark || | |
(themeProvider.themeMode == ThemeMode.system && isSystemDarkMode); | |
bool isDarkMode; | |
if (themeProvider.themeMode == ThemeMode.system){ | |
final brightness = | |
SchedulerBinding.instance.platformDispatcher.platformBrightness; | |
isDarkMode = brightness == Brightness.dark; | |
} else { | |
isDarkMode = themeProvider.themeMode == ThemeMode.dark; | |
} |