Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Nov 21, 2023

Close #1052

Test Code:
The main issue is resolved: slider.value now prints 100 (the max)

>>> import flet as ft
>>> slider = ft.Slider(divisions=100, value=150, min=0, max=100)
>>> slider.value
100

# but :

>>> repr(slider)
'Slider(value=150, min=0, max=100, divisions=100)'

Important Note:
As seen above the __repr__ or even __str__ still has value=150.
This is because the self.__attrs (where the props are stored) is not updated.

This could be solved by adding self.value = v (resetting the value / updating the self.__attrs) when verifying the limits in the value @property as follows:

@property
def value(self) -> OptionalNumber:
    v = self._get_attr("value", data_type="float")
    # verify limits
    if v < self.min:
        v = self.min
        self.value = v
    elif v > self.max:
        v = self.max
        self.value = v

    return v

but because we are in the @property, it will only be applied when slider.value is called.

>>> import flet as ft
>>> slider = ft.Slider(divisions=100, value=150, min=0, max=100)
>>> repr(slider)
'Slider(value=150, min=0, max=100, divisions=100)'
>>> slider.value
100
>>> repr(slider)
'Slider(value=100, min=0, max=100, divisions=100)'

Let me have your thoughts on the importance of this.

@FeodorFitsner FeodorFitsner merged commit e2abac0 into flet-dev:main Nov 21, 2023
@ndonkoHenri ndonkoHenri deleted the slider-bound branch November 22, 2023 10:36
zrr1999 pushed a commit to zrr1999/flet that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sliders can have out of bound value, if set manually

2 participants