Replies: 3 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
How about adding a theme_mode argument? Example: import flet as ft
from dataclasses import dataclass
@dataclass
class SliderColors:
active_bar_color: str
inactive_bar_color: str
@staticmethod
def dark():
return SliderColors(active_bar_color="#1f5eff", inactive_bar_color="#323741")
@staticmethod
def light():
return SliderColors(active_bar_color="#1f5eff", inactive_bar_color="#e8ebf4")
class Slider(ft.Slider):
def __init__(self, theme_mode=ft.ThemeMode.LIGHT, **kwargs):
super().__init__(**kwargs)
if theme_mode == ft.ThemeMode.LIGHT:
self.colors = SliderColors.light()
elif theme_mode == ft.ThemeMode.DARK:
self.colors = SliderColors.dark()
self.kwargs = kwargs
self.active_color = self.colors.active_bar_color
self.inactive_color = self.colors.inactive_bar_color
self.thumb_color = ft.colors.WHITE
self.overlay_color = ft.colors.with_opacity(0, "white")
def main(page: ft.Page):
page.theme_mode = ft.ThemeMode.DARK
slider = Slider(theme_mode=page.theme_mode)
page.add(slider)
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
2 replies
-
Hey, did you find a solution? The one by @vv2006-mc is specific for an object of Slider class, the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Question
How can I make a custom control responsive to theme changes, so it automatically adapts to the current page theme?
I tried using the
did_mount
method but that don't give me a way to listen for theme changing events.Code sample
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions