Slider does not show changed label value for keyboard users fix (#152886)
Fix issue to where keyboard users could not see visual indicator label of changed value in Slider Before: [Screen recording 2024-08-05 12.16.24 PM.webm](https://github.com/user-attachments/assets/89b99423-7856-4b25-86de-b211b2dbe178) After: [Screen recording 2024-08-05 12.38.20 PM.webm](https://github.com/user-attachments/assets/641f9065-8279-4b79-89b1-b5bcd3d691a8) Fixes https://github.com/flutter/flutter/issues/152884 Fixes b/340638215
This commit is contained in:
parent
ad268e2f89
commit
93b55edff1
@ -1818,6 +1818,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
|||||||
final double increase = increaseValue();
|
final double increase = increaseValue();
|
||||||
onChanged!(increase);
|
onChanged!(increase);
|
||||||
onChangeEnd!(increase);
|
onChangeEnd!(increase);
|
||||||
|
if (!_state.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state.showValueIndicator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1827,6 +1831,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
|||||||
final double decrease = decreaseValue();
|
final double decrease = decreaseValue();
|
||||||
onChanged!(decrease);
|
onChanged!(decrease);
|
||||||
onChangeEnd!(decrease);
|
onChangeEnd!(decrease);
|
||||||
|
if (!_state.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state.showValueIndicator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4443,4 +4443,109 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(valueIndicatorBox, paintsExactlyCountTimes(#drawPath, 1));
|
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();
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user