CupertinoSlider initialisation does not allow values less then zero/greater then 1
Duplicate Check
- [x] I have searched the opened issues and there are no duplicates
Describe the bug
TL;DR: Initialisations such as ft.CupertinoSlider(min=2, max=3) or ft.CupertinoSlider(min=0, max=3, value=2) throws errors.
When creating a new CupertinoSlider, it's not possible to set values to be less then zero or greater then one.
For example, you cannot create slider like this: ft.CupertinoSlider(min=0, max=255, value=127). you will get an AssertionError
This behavior seems to be due to the way object initialized. It does it in the order: value, min, max. Than means that the value checker in property fails to set a value, if it's out of the defoult [0.0 ... 1.0] range. For the same reason there does not seem to be a way to init a slider with min value greater then 1.0, even if max key is set and greater then min (it will throw an Assertion for setting min to be greater then current max, wich is 1.0 by defoult)
This is where this logic implemented [https://github.com/flet-dev/flet/blob/main/sdk/python/packages/flet/src/flet/core/cupertino_slider.py#L109]
I mark this as a bug since there are no indecation of this way of initialisation being unsupported, moreover, in the documentation [https://flet.dev/docs/controls/cupertinoslider/] the order of the arguments suggest that it's an expected way to create a slider with nondefault range and set value. If it is an expected behavior i think it should be stated in the docs.
Code sample
Code
import flet as ft
def main(page: ft.Page):
slider = ft.CupertinoSlider(
min=0,
max=255,
value=127,
)
page.add(slider)
page.update()
ft.app(main)
this snippet fails with "AssertionError: value must be less than or equal to max"
To reproduce
- Setup any python env with flet installed
- Create any CupertinoSlider slider with init values of valid range (min <= value <= max) where eather value key is not in the [0.0 ... 1.0] range or min key is greater then 1
Expected behavior
Slider created without errors (since the range is valid). Instead ether "AssertionError: min must be less than or equal to max" or "AssertionError: value must be less than or equal to max"
Operating System
Windows
Operating system details
Windows 11
Flet version
0.26.0
Regression
I'm not sure / I don't know
Suggestions
I would eather expect to have eather:
- value, max and min to be initialised at the same time (and checked for correctness after all three are set)
- Their order of the init to correspond to property order in https://flet.dev/docs/controls/cupertinoslider/
- This behavior stated in the docs
Logs
Logs
[Paste your logs here]
Additional details
My understanding is that it is not really common to do those checks in the controls initialisations. But this case does look very unintuitive and easy to fix.
I also don't think doing
slider = ft.CupertinoSlider()
slider.max = 5
sliider.min = 2
slider.value = 4
Is a reasonable way to go around this initialisation problem
I know a workaround where u set divisions in the slider here it can start from a float value like 0.25