-
Notifications
You must be signed in to change notification settings - Fork 145
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
feat: System Theme Mode #451
Conversation
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.
I think we should rework this from Stateful Widget to work with GetX state mangement.
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.
This is still a Stateful Widget, it will make more sense to use GetX to keep it consistent.
theme: isLightMode.value ? AppTheme.light : AppTheme.dark, | ||
); | ||
void _startBrightnessCheckTimer() { | ||
_brightnessCheckTimer = Timer.periodic(Duration(seconds: 2), (timer) { |
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.
This Timer is going to be resource intensive for something as simple as a theme change. We can just make it work on app startup and not keep it "real time"
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.
But if so then it wouln't check for light or dark difference right?
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.
Wait, as I understand this timer is to check if the the device's theme is dark or light and it updates the theme on the app right? The timer runs every 2 seconds to check this, right?
I think we can just set the app to the appropriate theme when it's opened up rather than having to change it in realtime.
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.
Correct me if I am wrong, but isn't that how system theme works? As in if my app in System mode, it needs to check if my device is in light or dark mode right? It is always listening for changes, If we are checking just at the start of the app then its going to be simply like a default light and dark mode yea?
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.
Maybe, but this timer is gonna be unnecessary at the minute. I think we should just set the appropriate theme when the app is restarted, we don't really need it to be real-time.
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.
Ok. Fine. I will make that change.
|
||
class ThemeController extends GetxController { | ||
var isLightMode = true.obs; | ||
final _secureStorageProvider = SecureStorageProvider(); | ||
|
||
late Timer _brightnessCheckTimer; | ||
bool isSystemModeActive = false; |
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.
You can just check this from the theme details that we're alreading storing, this variable would not be needed
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.
I tried that, but the problem was that, either the system mode text won't update, or else it won't change completely to light or dark issue. Weird issue but this was the most optimized way I found out
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.
Could you elaborate more on this? We are storing the theme details in storage and fetching it in onInit
so we should have access to the option chosen by the user, yes?
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.
In this existing method, we can retrieve the current theme settings. But it isn't working properly for the system mode. As in, all the elements/widgets are not changing accordingly. So I had to do it manually itself. For that I created a new variable. Again it is a weird issue, but this was the only work around for it. Its the optimal one for now.
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.
This is still a Stateful Widget, it will make more sense to use GetX to keep it consistent.
theme: isLightMode.value ? AppTheme.light : AppTheme.dark, | ||
); | ||
void _startBrightnessCheckTimer() { | ||
_brightnessCheckTimer = Timer.periodic(Duration(seconds: 2), (timer) { |
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.
Maybe, but this timer is gonna be unnecessary at the minute. I think we should just set the appropriate theme when the app is restarted, we don't really need it to be real-time.
|
||
class ThemeController extends GetxController { | ||
var isLightMode = true.obs; | ||
final _secureStorageProvider = SecureStorageProvider(); | ||
|
||
late Timer _brightnessCheckTimer; | ||
bool isSystemModeActive = false; |
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.
Could you elaborate more on this? We are storing the theme details in storage and fetching it in onInit
so we should have access to the option chosen by the user, yes?
@MarkisDev , I have made the changes. Now our app only looks for the system theme on the initial. No more periodic checks. When we directly retrieve the themes using existing method, system mode is not working properly. It is not change the entire widget. So what I did was, I made a systemenabled variable, after that I do a brightness check to find out if its dark or light. And apply the theme as theme.dark, at the same time maintaining the dropdown option as System, This is the most optimal method for now. |
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.
Just need some more clarifications before I can merge this in.
@@ -25,6 +26,26 @@ class ThemeValueTile extends StatefulWidget { | |||
} | |||
|
|||
class _ThemeValueTileState extends State<ThemeValueTile> { | |||
final _secureStorageProvider = SecureStorageProvider(); |
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.
I don't see the point of making multiple instances of SecureStorageProvider. It's declared as private in the theme controller, when it shouldn't be. Kindly make that change,
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.
I am sorry @MarkisDev but I am not getting you on this point.
@@ -25,6 +26,26 @@ class ThemeValueTile extends StatefulWidget { | |||
} | |||
|
|||
class _ThemeValueTileState extends State<ThemeValueTile> { |
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 this a Stateful widget? Could you please explain why this is declared as a stateful widget when GetX is being used for state management within this file?
Description
Our app now features a system theme mode, which will listen automatically to the changes in the system theme mode and apply that.
Fixes #427
Screenrecording
Screen_Recording_20240216_191346.1.mp4
Checklist