[a11y] Slider should respect bold text setting (#149053)
Fix https://github.com/flutter/flutter/issues/147600 internal GAR issue: b/316933135 reopen from #148435
This commit is contained in:
parent
7be97ab781
commit
8ff57091bc
@ -817,6 +817,11 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
?? MaterialStateProperty.resolveAs<Color?>(defaults.overlayColor, states);
|
||||
}
|
||||
|
||||
TextStyle valueIndicatorTextStyle = sliderTheme.valueIndicatorTextStyle ?? defaults.valueIndicatorTextStyle!;
|
||||
if (MediaQuery.boldTextOf(context)) {
|
||||
valueIndicatorTextStyle = valueIndicatorTextStyle.merge(const TextStyle(fontWeight: FontWeight.bold));
|
||||
}
|
||||
|
||||
sliderTheme = sliderTheme.copyWith(
|
||||
trackHeight: sliderTheme.trackHeight ?? defaults.trackHeight,
|
||||
activeTrackColor: widget.activeColor ?? sliderTheme.activeTrackColor ?? defaults.activeTrackColor,
|
||||
@ -839,7 +844,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
overlayShape: sliderTheme.overlayShape ?? defaultOverlayShape,
|
||||
valueIndicatorShape: valueIndicatorShape,
|
||||
showValueIndicator: sliderTheme.showValueIndicator ?? defaultShowValueIndicator,
|
||||
valueIndicatorTextStyle: sliderTheme.valueIndicatorTextStyle ?? defaults.valueIndicatorTextStyle,
|
||||
valueIndicatorTextStyle: valueIndicatorTextStyle,
|
||||
);
|
||||
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states)
|
||||
?? sliderTheme.mouseCursor?.resolve(states)
|
||||
|
@ -49,6 +49,36 @@ class LoggingThumbShape extends SliderComponentShape {
|
||||
}
|
||||
}
|
||||
|
||||
// A value indicator shape to log labelPainter text.
|
||||
class LoggingValueIndicatorShape extends SliderComponentShape {
|
||||
LoggingValueIndicatorShape(this.logLabel);
|
||||
|
||||
final List<InlineSpan> logLabel;
|
||||
|
||||
@override
|
||||
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
|
||||
return const Size(10.0, 10.0);
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(
|
||||
PaintingContext context,
|
||||
Offset offset, {
|
||||
required Animation<double> activationAnimation,
|
||||
required Animation<double> enableAnimation,
|
||||
required bool isDiscrete,
|
||||
required TextPainter labelPainter,
|
||||
required RenderBox parentBox,
|
||||
required SliderThemeData sliderTheme,
|
||||
required TextDirection textDirection,
|
||||
required double value,
|
||||
required double textScaleFactor,
|
||||
required Size sizeWithOverflow,
|
||||
}) {
|
||||
logLabel.add(labelPainter.text!);
|
||||
}
|
||||
}
|
||||
|
||||
class TallSliderTickMarkShape extends SliderTickMarkShape {
|
||||
@override
|
||||
Size getPreferredSize({required SliderThemeData sliderTheme, required bool isEnabled}) {
|
||||
@ -975,6 +1005,79 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Slider value indicator respects bold text', (WidgetTester tester) async {
|
||||
final Key sliderKey = UniqueKey();
|
||||
double value = 0.0;
|
||||
final List<InlineSpan> log = <InlineSpan>[];
|
||||
final LoggingValueIndicatorShape loggingValueIndicatorShape = LoggingValueIndicatorShape(log);
|
||||
|
||||
Widget buildSlider({ bool boldText = false }) {
|
||||
return MaterialApp(
|
||||
home: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return MediaQuery(
|
||||
data: MediaQueryData(boldText: boldText),
|
||||
child: Material(
|
||||
child: Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
sliderTheme: Theme.of(context).sliderTheme.copyWith(
|
||||
showValueIndicator: ShowValueIndicator.always,
|
||||
valueIndicatorShape: loggingValueIndicatorShape,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: OverflowBox(
|
||||
maxWidth: double.infinity,
|
||||
maxHeight: double.infinity,
|
||||
child: Slider(
|
||||
key: sliderKey,
|
||||
max: 100.0,
|
||||
divisions: 4,
|
||||
label: '${value.round()}',
|
||||
value: value,
|
||||
onChanged: (double newValue) {
|
||||
setState(() {
|
||||
value = newValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
// Normal text
|
||||
await tester.pumpWidget(buildSlider());
|
||||
Offset center = tester.getCenter(find.byType(Slider));
|
||||
TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(log.last.toPlainText(), '50');
|
||||
expect(log.last.style!.fontWeight, FontWeight.w500);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Bold text
|
||||
await tester.pumpWidget(buildSlider(boldText: true));
|
||||
center = tester.getCenter(find.byType(Slider));
|
||||
gesture = await tester.startGesture(center);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(log.last.toPlainText(), '50');
|
||||
expect(log.last.style!.fontWeight, FontWeight.w700);
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('Tick marks are skipped when they are too dense', (WidgetTester tester) async {
|
||||
Widget buildSlider({
|
||||
required int divisions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user