Unverified Commit ad8c9978 authored by nt4f04uNd's avatar nt4f04uNd Committed by GitHub

Fix RangeSlider notifies start and end twice when participates in gesture arena (#128674)

Fixes https://github.com/flutter/flutter/issues/128433

This PR applies the same fix as we did for Slider https://github.com/flutter/flutter/pull/82152
parent 05d1cde0
...@@ -833,7 +833,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -833,7 +833,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
..team = team ..team = team
..onTapDown = _handleTapDown ..onTapDown = _handleTapDown
..onTapUp = _handleTapUp ..onTapUp = _handleTapUp
..onTapCancel = _handleTapCancel
..gestureSettings = gestureSettings; ..gestureSettings = gestureSettings;
_overlayAnimation = CurvedAnimation( _overlayAnimation = CurvedAnimation(
parent: _state.overlayController, parent: _state.overlayController,
...@@ -1221,6 +1220,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1221,6 +1220,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
} }
void _startInteraction(Offset globalPosition) { void _startInteraction(Offset globalPosition) {
if (_active) {
return;
}
_state.showValueIndicator(); _state.showValueIndicator();
final double tapValue = clampDouble(_getValueFromGlobalPosition(globalPosition), 0.0, 1.0); final double tapValue = clampDouble(_getValueFromGlobalPosition(globalPosition), 0.0, 1.0);
_lastThumbSelection = sliderTheme.thumbSelector!(textDirection, values, tapValue, _thumbSize, size, 0); _lastThumbSelection = sliderTheme.thumbSelector!(textDirection, values, tapValue, _thumbSize, size, 0);
...@@ -1333,10 +1336,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix ...@@ -1333,10 +1336,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
_endInteraction(); _endInteraction();
} }
void _handleTapCancel() {
_endInteraction();
}
@override @override
bool hitTestSelf(Offset position) => true; bool hitTestSelf(Offset position) => true;
......
...@@ -2540,4 +2540,45 @@ void main() { ...@@ -2540,4 +2540,45 @@ void main() {
isNot(paints..circle(color: draggedColor)), isNot(paints..circle(color: draggedColor)),
); );
}); });
testWidgets('RangeSlider onChangeStart and onChangeEnd fire once', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/128433
int startFired = 0;
int endFired = 0;
await tester.pumpWidget(
MaterialApp(
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: GestureDetector(
onHorizontalDragUpdate: (_) { },
child: RangeSlider(
values: const RangeValues(40, 80),
max: 100,
onChanged: (RangeValues newValue) { },
onChangeStart: (RangeValues value) {
startFired += 1;
},
onChangeEnd: (RangeValues value) {
endFired += 1;
},
),
),
),
),
),
),
);
await tester.timedDragFrom(
tester.getTopLeft(find.byType(RangeSlider)),
const Offset(100.0, 0.0),
const Duration(milliseconds: 500),
);
expect(startFired, equals(1));
expect(endFired, equals(1));
});
} }
...@@ -1644,7 +1644,7 @@ void main() { ...@@ -1644,7 +1644,7 @@ void main() {
}); });
testWidgets('ListWheelScrollView does not crash and does not allow taps on children that were laid out, but not painted', (WidgetTester tester) async { testWidgets('ListWheelScrollView does not crash and does not allow taps on children that were laid out, but not painted', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/12649 // Regression test for https://github.com/flutter/flutter/issues/126491
final FixedExtentScrollController controller = FixedExtentScrollController(); final FixedExtentScrollController controller = FixedExtentScrollController();
final List<int> children = List<int>.generate(100, (int index) => index); final List<int> children = List<int>.generate(100, (int index) => index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment