Skip to content

Commit 52c4db8

Browse files
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 flutter/flutter#123313
1 parent 16e6be8 commit 52c4db8

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
15121512
_state.interactionTimer?.cancel();
15131513
_state.interactionTimer = Timer(_minimumInteractionTime * timeDilation, () {
15141514
_state.interactionTimer = null;
1515-
if (!_active && !hasFocus &&
1516-
_state.valueIndicatorController.status == AnimationStatus.completed) {
1515+
if (!_active && _state.valueIndicatorController.status == AnimationStatus.completed) {
15171516
_state.valueIndicatorController.reverse();
15181517
}
15191518
});

packages/flutter/test/material/slider_test.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,56 @@ void main() {
35093509
);
35103510
}, variant: TargetPlatformVariant.desktop());
35113511

3512+
testWidgets('Value indicator disappears after adjusting the slider', (WidgetTester tester) async {
3513+
// This is a regression test for https://github.com/flutter/flutter/issues/123313.
3514+
final ThemeData theme = ThemeData(useMaterial3: true);
3515+
const double currentValue = 0.5;
3516+
await tester.pumpWidget(MaterialApp(
3517+
theme: theme,
3518+
home: Material(
3519+
child: Center(
3520+
child: Slider(
3521+
value: currentValue,
3522+
divisions: 5,
3523+
label: currentValue.toStringAsFixed(1),
3524+
onChanged: (double value) {},
3525+
),
3526+
),
3527+
),
3528+
));
3529+
3530+
// Slider does not show value indicator initially.
3531+
await tester.pumpAndSettle();
3532+
RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
3533+
expect(
3534+
valueIndicatorBox,
3535+
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
3536+
);
3537+
3538+
final Offset sliderCenter = tester.getCenter(find.byType(Slider));
3539+
final Offset tapLocation = Offset(sliderCenter.dx + 50, sliderCenter.dy);
3540+
3541+
// Tap the slider to bring up the value indicator.
3542+
await tester.tapAt(tapLocation);
3543+
await tester.pumpAndSettle();
3544+
3545+
// Value indicator is visible.
3546+
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
3547+
expect(
3548+
valueIndicatorBox,
3549+
paints..scale()..path(color: theme.colorScheme.primary),
3550+
);
3551+
3552+
// Wait for the value indicator to disappear.
3553+
await tester.pumpAndSettle(const Duration(seconds: 2));
3554+
3555+
// Value indicator is no longer visible.
3556+
expect(
3557+
valueIndicatorBox,
3558+
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
3559+
);
3560+
});
3561+
35123562
testWidgets('Value indicator remains when Slider is in focus on desktop', (WidgetTester tester) async {
35133563
double value = 0.5;
35143564
final FocusNode focusNode = FocusNode();

0 commit comments

Comments
 (0)