diff --git a/packages/flutter/lib/src/cupertino/slider.dart b/packages/flutter/lib/src/cupertino/slider.dart index 29e82ca697..90fd190c72 100644 --- a/packages/flutter/lib/src/cupertino/slider.dart +++ b/packages/flutter/lib/src/cupertino/slider.dart @@ -331,6 +331,7 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { _position.animateTo(newValue, curve: Curves.fastOutSlowIn); else _position.value = newValue; + markNeedsSemanticsUpdate(); } int get divisions => _divisions; @@ -503,8 +504,12 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { config.isSemanticBoundary = isInteractive; if (isInteractive) { + config.textDirection = textDirection; config.onIncrease = _increaseAction; config.onDecrease = _decreaseAction; + config.value = '${(value * 100).round()}%'; + config.increasedValue = '${((value + _semanticActionUnit).clamp(0.0, 1.0) * 100).round()}%'; + config.decreasedValue = '${((value - _semanticActionUnit).clamp(0.0, 1.0) * 100).round()}%'; } } diff --git a/packages/flutter/test/cupertino/slider_test.dart b/packages/flutter/test/cupertino/slider_test.dart index 855e7d6c13..2dd543818e 100644 --- a/packages/flutter/test/cupertino/slider_test.dart +++ b/packages/flutter/test/cupertino/slider_test.dart @@ -289,6 +289,10 @@ void main() { children: [ new TestSemantics.rootChild( id: 1, + value: '50%', + increasedValue: '60%', + decreasedValue: '40%', + textDirection: TextDirection.ltr, actions: SemanticsAction.decrease.index | SemanticsAction.increase.index, ), ] @@ -314,4 +318,45 @@ void main() { semantics.dispose(); }); + + testWidgets('Slider Semantics can be updated', (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + double value = 0.5; + await tester.pumpWidget(new Directionality( + textDirection: TextDirection.ltr, + child: new CupertinoSlider( + value: value, + onChanged: (double v) { }, + ), + )); + + expect(tester.getSemanticsData(find.byType(CupertinoSlider)), matchesSemanticsData( + hasIncreaseAction: true, + hasDecreaseAction: true, + value: '50%', + increasedValue: '60%', + decreasedValue: '40%', + textDirection: TextDirection.ltr, + )); + + value = 0.6; + await tester.pumpWidget(new Directionality( + textDirection: TextDirection.ltr, + child: new CupertinoSlider( + value: value, + onChanged: (double v) { }, + ), + )); + + expect(tester.getSemanticsData(find.byType(CupertinoSlider)), matchesSemanticsData( + hasIncreaseAction: true, + hasDecreaseAction: true, + value: '60%', + increasedValue: '70%', + decreasedValue: '50%', + textDirection: TextDirection.ltr, + )); + + handle.dispose(); + }); } diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index f88354ed10..96f1a808be 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -304,6 +304,8 @@ Matcher matchesSemanticsData({ String label, String hint, String value, + String increasedValue, + String decreasedValue, TextDirection textDirection, Rect rect, Size size, @@ -447,6 +449,8 @@ Matcher matchesSemanticsData({ label: label, hint: hint, value: value, + increasedValue: increasedValue, + decreasedValue: decreasedValue, actions: actions, flags: flags, textDirection: textDirection, @@ -1514,6 +1518,8 @@ class _MatchesSemanticsData extends Matcher { _MatchesSemanticsData({ this.label, this.value, + this.increasedValue, + this.decreasedValue, this.hint, this.flags, this.actions, @@ -1527,6 +1533,8 @@ class _MatchesSemanticsData extends Matcher { final String label; final String value; final String hint; + final String increasedValue; + final String decreasedValue; final SemanticsHintOverrides hintOverrides; final List actions; final List customActions; @@ -1544,6 +1552,10 @@ class _MatchesSemanticsData extends Matcher { description.add('with value: $value '); if (hint != null) description.add('with hint: $hint '); + if (increasedValue != null) + description.add('with increasedValue: $increasedValue'); + if (decreasedValue != null) + description.add('with decreasedValue: $decreasedValue'); if (actions != null) description.add('with actions:').addDescriptionOf(actions); if (flags != null) @@ -1573,6 +1585,10 @@ class _MatchesSemanticsData extends Matcher { return failWithDescription(matchState, 'hint was: ${data.hint}'); if (value != null && value != data.value) return failWithDescription(matchState, 'value was: ${data.value}'); + if (increasedValue != null && increasedValue != data.increasedValue) + return failWithDescription(matchState, 'increasedValue was: ${data.increasedValue}'); + if (decreasedValue != null && decreasedValue != data.decreasedValue) + return failWithDescription(matchState, 'decreasedValue was: ${data.decreasedValue}'); if (textDirection != null && textDirection != data.textDirection) return failWithDescription(matchState, 'textDirection was: $textDirection'); if (rect != null && rect != data.rect) diff --git a/packages/flutter_test/test/matchers_test.dart b/packages/flutter_test/test/matchers_test.dart index 24caf0f6d8..1ad12adcb1 100644 --- a/packages/flutter_test/test/matchers_test.dart +++ b/packages/flutter_test/test/matchers_test.dart @@ -398,6 +398,8 @@ void main() { label: 'foo', hint: 'bar', value: 'baz', + increasedValue: 'a', + decreasedValue: 'b', textDirection: TextDirection.rtl, onTapHint: 'scan', onLongPressHint: 'fill', @@ -412,6 +414,8 @@ void main() { label: 'foo', hint: 'bar', value: 'baz', + increasedValue: 'a', + decreasedValue: 'b', textDirection: TextDirection.rtl, hasTapAction: true, hasLongPressAction: true,