Fixed slider value indicator not disappearing after a bit on desktop platform when slider is clicked not dragged (#128137)
In slider.dart within the _startInteraction method and within the below conditional. "if (!_active && !hasFocus && _state.valueIndicatorController.status == AnimationStatus.completed)" **Changed to:** "f (!_active && _state.valueIndicatorController.status == AnimationStatus.completed)" This allows the value indicator to disappear after a bit when clicked instead of dragged on Desktop platform. I also added a test in slider_test.dart to detect the bug if it ever returns. Fixes https://github.com/flutter/flutter/issues/123313
This commit is contained in:
parent
16e6be8b39
commit
52c4db8d33
@ -1512,8 +1512,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
_state.interactionTimer?.cancel();
|
||||
_state.interactionTimer = Timer(_minimumInteractionTime * timeDilation, () {
|
||||
_state.interactionTimer = null;
|
||||
if (!_active && !hasFocus &&
|
||||
_state.valueIndicatorController.status == AnimationStatus.completed) {
|
||||
if (!_active && _state.valueIndicatorController.status == AnimationStatus.completed) {
|
||||
_state.valueIndicatorController.reverse();
|
||||
}
|
||||
});
|
||||
|
@ -3509,6 +3509,56 @@ void main() {
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
|
||||
testWidgets('Value indicator disappears after adjusting the slider', (WidgetTester tester) async {
|
||||
// This is a regression test for https://github.com/flutter/flutter/issues/123313.
|
||||
final ThemeData theme = ThemeData(useMaterial3: true);
|
||||
const double currentValue = 0.5;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: theme,
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: Slider(
|
||||
value: currentValue,
|
||||
divisions: 5,
|
||||
label: currentValue.toStringAsFixed(1),
|
||||
onChanged: (double value) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Slider does not show value indicator initially.
|
||||
await tester.pumpAndSettle();
|
||||
RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
|
||||
);
|
||||
|
||||
final Offset sliderCenter = tester.getCenter(find.byType(Slider));
|
||||
final Offset tapLocation = Offset(sliderCenter.dx + 50, sliderCenter.dy);
|
||||
|
||||
// Tap the slider to bring up the value indicator.
|
||||
await tester.tapAt(tapLocation);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Value indicator is visible.
|
||||
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
paints..scale()..path(color: theme.colorScheme.primary),
|
||||
);
|
||||
|
||||
// Wait for the value indicator to disappear.
|
||||
await tester.pumpAndSettle(const Duration(seconds: 2));
|
||||
|
||||
// Value indicator is no longer visible.
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Value indicator remains when Slider is in focus on desktop', (WidgetTester tester) async {
|
||||
double value = 0.5;
|
||||
final FocusNode focusNode = FocusNode();
|
||||
|
Loading…
x
Reference in New Issue
Block a user