Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
33c4cd0f
Unverified
Commit
33c4cd0f
authored
Aug 14, 2018
by
Jonah Williams
Committed by
GitHub
Aug 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add semantics to cupertino slider (#20476)
parent
5311dff1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
0 deletions
+70
-0
slider.dart
packages/flutter/lib/src/cupertino/slider.dart
+5
-0
slider_test.dart
packages/flutter/test/cupertino/slider_test.dart
+45
-0
matchers.dart
packages/flutter_test/lib/src/matchers.dart
+16
-0
matchers_test.dart
packages/flutter_test/test/matchers_test.dart
+4
-0
No files found.
packages/flutter/lib/src/cupertino/slider.dart
View file @
33c4cd0f
...
...
@@ -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()}
%'
;
}
}
...
...
packages/flutter/test/cupertino/slider_test.dart
View file @
33c4cd0f
...
...
@@ -289,6 +289,10 @@ void main() {
children:
<
TestSemantics
>[
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
();
});
}
packages/flutter_test/lib/src/matchers.dart
View file @
33c4cd0f
...
...
@@ -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
<
SemanticsAction
>
actions
;
final
List
<
CustomSemanticsAction
>
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
)
...
...
packages/flutter_test/test/matchers_test.dart
View file @
33c4cd0f
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment