Skip to content
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

How can I check whether the system theme is dark or light mode? #1630

Closed
1 task done
FeodorFitsner opened this issue Jul 25, 2023 Discussed in #1627 · 2 comments
Closed
1 task done

How can I check whether the system theme is dark or light mode? #1630

FeodorFitsner opened this issue Jul 25, 2023 Discussed in #1627 · 2 comments
Labels
enhancement Improvement/Optimization help wanted Extra attention is needed

Comments

@FeodorFitsner
Copy link
Contributor

Discussed in #1627

Originally posted by BC-clegras July 24, 2023

Question

I have a button in my code that switches between light mode and dark mode, which works great, but I would like to know how I can check if the system theme is dark or light.

Right now, I hardcode page.theme_mode = ft.ThemeMode.LIGHT, since the code for my button assumes that the system starts in light more. I would love to use the ft.ThemeMode.SYSTEM property, but I can't figure out how to check if system means dark or light mode, and therefore there will always be a scenario where an extra click will be needed at the start if the user wants to switch between light and dark mode.

Basically, I would like to be able to know what state the app starts in so I can make the button I use for dark mode have the correct icon and tooltip at startup.

Code sample

# This button is in my app bar
ft.IconButton(
    ft.icons.DARK_MODE_ROUNDED,
    tooltip="Switch to dark mode",
    on_click=self.toggle_dark_mode,
),

# The function that gets called when the button is clicked
def toggle_dark_mode(self, e):
    if self.page.theme_mode == ft.ThemeMode.DARK:
        e.control.icon = ft.icons.DARK_MODE_ROUNDED
        e.control.tooltip = "Switch to dark mode"
        self.page.theme_mode = ft.ThemeMode.LIGHT

    else:
        e.control.icon = ft.icons.WB_SUNNY_ROUNDED
        e.control.tooltip = "Switch to light mode"
        self.page.theme_mode = ft.ThemeMode.DARK

    self.page.update()

Error message

No response

------------------------------------------------------

  • I have searched for answers to my question both in the issues and in previous discussions.
@FeodorFitsner FeodorFitsner added enhancement Improvement/Optimization help wanted Extra attention is needed labels Jul 25, 2023
@andrerotband
Copy link

You can see on property bellow:

page.platform_brightness

Good luck!

@BC-clegras
Copy link

awesome, thanks a lot!

zrr1999 pushed a commit to zrr1999/flet that referenced this issue Jul 17, 2024
* Added `page.debug` and `page.platform_brightness` props

Close flet-dev#1649, close flet-dev#1630

* Store session ID in `window.name`

Fix flet-dev#1629

* Do not assign random port on Windows with `--ios` flag

Fix flet-dev#1620

* Update local_connection.py

* Build Android QR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants