Slider shows visual label of value on focus (#152960)
Fixed issue to where value indicator label is not shown to user when initially focused. Before: [Screen recording 2024-08-05 12.16.24 PM.webm](https://github.com/user-attachments/assets/806e94d7-7c6c-40e5-93af-dbf2fb9e0dd4) After: https://screencast.googleplex.com/cast/NTY5NzIzMTYxNjIxMjk5MnxkY2IyMGNkYi1iZA Fixes https://github.com/flutter/flutter/issues/113538
This commit is contained in:
parent
ed40925bb1
commit
51c640297f
@ -713,6 +713,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
if (focused != _focused) {
|
||||
setState(() { _focused = focused; });
|
||||
}
|
||||
showValueIndicator();
|
||||
}
|
||||
|
||||
bool _hovering = false;
|
||||
|
@ -4484,12 +4484,12 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
// Slider does not show value indicator initially.
|
||||
// Slider shows value indicator initially on focus.
|
||||
await tester.pumpAndSettle();
|
||||
RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
|
||||
paints..scale()..path(color: theme.colorScheme.primary),
|
||||
);
|
||||
|
||||
// Right arrow (increase)
|
||||
@ -4548,4 +4548,54 @@ void main() {
|
||||
paints..scale()..path(color: theme.colorScheme.primary),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
|
||||
testWidgets('Value indicator label is shown when focused', (WidgetTester tester) async {
|
||||
double value = 0.5;
|
||||
final FocusNode focusNode = FocusNode();
|
||||
addTearDown(focusNode.dispose);
|
||||
|
||||
Widget buildApp() {
|
||||
return MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return Slider(
|
||||
value: value,
|
||||
focusNode: focusNode,
|
||||
divisions: 5,
|
||||
label: value.toStringAsFixed(1),
|
||||
onChanged:
|
||||
(double newValue) {
|
||||
setState(() {
|
||||
value = newValue;
|
||||
});
|
||||
}
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
await tester.pumpWidget(buildApp());
|
||||
|
||||
// Slider does not show value indicator without focus.
|
||||
await tester.pumpAndSettle();
|
||||
expect(focusNode.hasFocus, false);
|
||||
RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
isNot(paints..path(color: const Color(0xff000000))..paragraph()),
|
||||
);
|
||||
|
||||
focusNode.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
expect(focusNode.hasFocus, true);
|
||||
|
||||
// Slider shows value indicator when focused.
|
||||
valueIndicatorBox = tester.renderObject(find.byType(Overlay));
|
||||
expect(
|
||||
valueIndicatorBox,
|
||||
paints..path(color: const Color(0xff000000))..paragraph(),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user