Skip to content

Slider does not show changed label value for keyboard users fix #152886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 6, 2024
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/material/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final double increase = increaseValue();
onChanged!(increase);
onChangeEnd!(increase);
_state.showValueIndicator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check whether _state is mounted before? Like:

    if (!_state.mounted) {
      return;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Added check like code snippet in lines 1493 - 1495.

}
}

Expand All @@ -1827,6 +1828,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final double decrease = decreaseValue();
onChanged!(decrease);
onChangeEnd!(decrease);
_state.showValueIndicator();
}
}

Expand Down
105 changes: 105 additions & 0 deletions packages/flutter/test/material/slider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4443,4 +4443,109 @@ void main() {
await tester.pumpAndSettle();
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));
});

testWidgets('Slider value indicator is shown when using arrow keys', (WidgetTester tester) async {
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
final ThemeData theme = ThemeData(useMaterial3: true);
double startValue = 0.0;
double currentValue = 0.5;
double endValue = 0.0;

await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Center(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
return Slider(
value: currentValue,
divisions: 5,
label: currentValue.toStringAsFixed(1),
onChangeStart: (double newValue) {
setState(() {
startValue = newValue;
});
},
onChanged: (double newValue) {
setState(() {
currentValue = newValue;
});
},
onChangeEnd: (double newValue) {
setState(() {
endValue = newValue;
});
},
autofocus: true,
);
}),
),
),
),
);

// 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)),
);

// Right arrow (increase)
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.pumpAndSettle();
expect(startValue, 0.6);
expect(currentValue.toStringAsFixed(1), '0.8');
expect(endValue.toStringAsFixed(1), '0.8');

// Value indicator is visible.
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
expect(
valueIndicatorBox,
paints..scale()..path(color: theme.colorScheme.primary),
);

// Left arrow (decrease)
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await tester.pumpAndSettle();
expect(startValue, 0.8);
expect(currentValue.toStringAsFixed(1), '0.6');
expect(endValue.toStringAsFixed(1), '0.6');

// Value indicator is still visible.
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
expect(
valueIndicatorBox,
paints..scale()..path(color: theme.colorScheme.primary),
);

// Up arrow (increase)
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.pumpAndSettle();
expect(startValue, 0.6);
expect(currentValue.toStringAsFixed(1), '0.8');
expect(endValue.toStringAsFixed(1), '0.8');

// Value indicator is still visible.
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
expect(
valueIndicatorBox,
paints..scale()..path(color: theme.colorScheme.primary),
);

// Down arrow (decrease)
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pumpAndSettle();
expect(startValue, 0.8);
expect(currentValue.toStringAsFixed(1), '0.6');
expect(endValue.toStringAsFixed(1), '0.6');

// Value indicator is still visible.
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
expect(
valueIndicatorBox,
paints..scale()..path(color: theme.colorScheme.primary),
);
}, variant: TargetPlatformVariant.desktop());
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy