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
This commit is contained in:
nt4f04uNd 2023-06-12 21:20:11 +06:00 committed by GitHub
parent 05d1cde0dd
commit ad8c997817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 6 deletions

View File

@ -833,7 +833,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
..team = team
..onTapDown = _handleTapDown
..onTapUp = _handleTapUp
..onTapCancel = _handleTapCancel
..gestureSettings = gestureSettings;
_overlayAnimation = CurvedAnimation(
parent: _state.overlayController,
@ -1221,6 +1220,10 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
}
void _startInteraction(Offset globalPosition) {
if (_active) {
return;
}
_state.showValueIndicator();
final double tapValue = clampDouble(_getValueFromGlobalPosition(globalPosition), 0.0, 1.0);
_lastThumbSelection = sliderTheme.thumbSelector!(textDirection, values, tapValue, _thumbSize, size, 0);
@ -1333,10 +1336,6 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
_endInteraction();
}
void _handleTapCancel() {
_endInteraction();
}
@override
bool hitTestSelf(Offset position) => true;

View File

@ -2540,4 +2540,45 @@ void main() {
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));
});
}

View File

@ -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 {
// 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 List<int> children = List<int>.generate(100, (int index) => index);