Skip to content

Commit a1d2443

Browse files
authored
Fix render problem on Slider (flutter#15039)
Fixes a small rendering problem when dragging the slider, as well as a couple of small bugs (de-duping of value changes, and actually using a parameter passed to _unlerp).
1 parent b90659c commit a1d2443

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/flutter/lib/src/material/slider.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
239239

240240
void _handleChanged(double value) {
241241
assert(widget.onChanged != null);
242-
final double transformedValue = _lerp(value);
243-
widget.onChanged(transformedValue);
242+
final double lerpValue = _lerp(value);
243+
if (lerpValue != widget.value) {
244+
widget.onChanged(lerpValue);
245+
}
244246
}
245247

246248
// Returns a number between min and max, proportional to value, which must
@@ -255,7 +257,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
255257
double _unlerp(double value) {
256258
assert(value <= widget.max);
257259
assert(value >= widget.min);
258-
return widget.max > widget.min ? (widget.value - widget.min) / (widget.max - widget.min) : 0.0;
260+
return widget.max > widget.min ? (value - widget.min) / (widget.max - widget.min) : 0.0;
259261
}
260262

261263
@override
@@ -380,12 +382,13 @@ class _RenderSlider extends RenderBox {
380382
..team = team
381383
..onStart = _handleDragStart
382384
..onUpdate = _handleDragUpdate
383-
..onEnd = _handleDragEnd;
385+
..onEnd = _handleDragEnd
386+
..onCancel = _endInteraction;
384387
_tap = new TapGestureRecognizer()
385388
..team = team
386-
..onTapCancel = _endInteraction
387389
..onTapDown = _handleTapDown
388-
..onTapUp = _handleTapUp;
390+
..onTapUp = _handleTapUp
391+
..onTapCancel = _endInteraction;
389392
_reaction = new CurvedAnimation(parent: state.reactionController, curve: Curves.fastOutSlowIn)
390393
..addListener(markNeedsPaint);
391394
state.enableController.value = isInteractive ? 1.0 : 0.0;
@@ -586,6 +589,7 @@ class _RenderSlider extends RenderBox {
586589
break;
587590
}
588591
onChanged(_discretize(_currentDragValue));
592+
markNeedsPaint();
589593
}
590594
}
591595

0 commit comments

Comments
 (0)