Skip to content

Commit 63b9bff

Browse files
committed
Slider.round to round slider value on a label
Fix #1045
1 parent 649b294 commit 63b9bff

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

package/lib/src/controls/slider.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class _SliderControlState extends State<SliderControl> {
8989
double min = widget.control.attrDouble("min", 0)!;
9090
double max = widget.control.attrDouble("max", 1)!;
9191
int? divisions = widget.control.attrInt("divisions");
92+
int round = widget.control.attrInt("round", 0)!;
9293

9394
final server = FletAppServices.of(context).server;
9495

@@ -111,7 +112,8 @@ class _SliderControlState extends State<SliderControl> {
111112
min: min,
112113
max: max,
113114
divisions: divisions,
114-
label: label?.replaceAll("{value}", _value.toString()),
115+
label:
116+
label?.replaceAll("{value}", _value.toStringAsFixed(round)),
115117
activeColor: HexColor.fromString(Theme.of(context),
116118
widget.control.attrString("activeColor", "")!),
117119
inactiveColor: HexColor.fromString(Theme.of(context),

sdk/python/packages/flet-core/src/flet_core/slider.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
min: OptionalNumber = None,
7373
max: OptionalNumber = None,
7474
divisions: Optional[int] = None,
75+
round: Optional[int] = None,
7576
autofocus: Optional[bool] = None,
7677
active_color: Optional[str] = None,
7778
inactive_color: Optional[str] = None,
@@ -115,6 +116,7 @@ def __init__(
115116
self.min = min
116117
self.max = max
117118
self.divisions = divisions
119+
self.round = round
118120
self.autofocus = autofocus
119121
self.active_color = active_color
120122
self.inactive_color = inactive_color
@@ -164,7 +166,7 @@ def max(self) -> OptionalNumber:
164166
def max(self, value: OptionalNumber):
165167
self._set_attr("max", value)
166168

167-
# step
169+
# divisions
168170
@property
169171
def divisions(self) -> Optional[int]:
170172
return self._get_attr("divisions")
@@ -173,6 +175,15 @@ def divisions(self) -> Optional[int]:
173175
def divisions(self, value: Optional[int]):
174176
self._set_attr("divisions", value)
175177

178+
# round
179+
@property
180+
def round(self) -> Optional[int]:
181+
return self._get_attr("round")
182+
183+
@round.setter
184+
def round(self, value: Optional[int]):
185+
self._set_attr("round", value)
186+
176187
# autofocus
177188
@property
178189
def autofocus(self) -> Optional[bool]:

0 commit comments

Comments
 (0)