You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 barft.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 clickeddeftoggle_dark_mode(self, e):
ifself.page.theme_mode==ft.ThemeMode.DARK:
e.control.icon=ft.icons.DARK_MODE_ROUNDEDe.control.tooltip="Switch to dark mode"self.page.theme_mode=ft.ThemeMode.LIGHTelse:
e.control.icon=ft.icons.WB_SUNNY_ROUNDEDe.control.tooltip="Switch to light mode"self.page.theme_mode=ft.ThemeMode.DARKself.page.update()
* Added `page.debug` and `page.platform_brightness` props
Closeflet-dev#1649, closeflet-dev#1630
* Store session ID in `window.name`
Fixflet-dev#1629
* Do not assign random port on Windows with `--ios` flag
Fixflet-dev#1620
* Update local_connection.py
* Build Android QR
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 theft.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
Error message
No response
------------------------------------------------------
The text was updated successfully, but these errors were encountered: