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
82415e64
Unverified
Commit
82415e64
authored
Jul 30, 2018
by
Jonah Williams
Committed by
GitHub
Jul 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add semantic label to image icon and exclude semantics from image widget (#19970)
parent
a2019802
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
10 deletions
+50
-10
image_icon.dart
packages/flutter/lib/src/widgets/image_icon.dart
+28
-10
image_icon_test.dart
packages/flutter/test/widgets/image_icon_test.dart
+22
-0
No files found.
packages/flutter/lib/src/widgets/image_icon.dart
View file @
82415e64
...
...
@@ -26,7 +26,8 @@ class ImageIcon extends StatelessWidget {
const
ImageIcon
(
this
.
image
,
{
Key
key
,
this
.
size
,
this
.
color
this
.
color
,
this
.
semanticLabel
,
})
:
super
(
key:
key
);
/// The image to display as the icon.
...
...
@@ -53,14 +54,27 @@ class ImageIcon extends StatelessWidget {
/// [IconTheme], if any.
final
Color
color
;
/// Semantic label for the icon.
///
/// Announced in accessibility modes (e.g TalkBack/VoiceOver).
/// This label does not show in the UI.
///
/// See also:
///
/// * [Semantics.label], which is set to [semanticLabel] in the underlying
/// [Semantics] widget.
final
String
semanticLabel
;
@override
Widget
build
(
BuildContext
context
)
{
final
IconThemeData
iconTheme
=
IconTheme
.
of
(
context
);
final
double
iconSize
=
size
??
iconTheme
.
size
;
if
(
image
==
null
)
return
new
SizedBox
(
width:
iconSize
,
height:
iconSize
);
return
new
Semantics
(
label:
semanticLabel
,
child:
SizedBox
(
width:
iconSize
,
height:
iconSize
)
);
final
double
iconOpacity
=
iconTheme
.
opacity
;
Color
iconColor
=
color
??
iconTheme
.
color
;
...
...
@@ -68,13 +82,17 @@ class ImageIcon extends StatelessWidget {
if
(
iconOpacity
!=
null
&&
iconOpacity
!=
1.0
)
iconColor
=
iconColor
.
withOpacity
(
iconColor
.
opacity
*
iconOpacity
);
return
new
Image
(
image:
image
,
width:
iconSize
,
height:
iconSize
,
color:
iconColor
,
fit:
BoxFit
.
scaleDown
,
alignment:
Alignment
.
center
,
return
new
Semantics
(
label:
semanticLabel
,
child:
Image
(
image:
image
,
width:
iconSize
,
height:
iconSize
,
color:
iconColor
,
fit:
BoxFit
.
scaleDown
,
alignment:
Alignment
.
center
,
excludeFromSemantics:
true
,
),
);
}
...
...
packages/flutter/test/widgets/image_icon_test.dart
View file @
82415e64
...
...
@@ -96,4 +96,26 @@ void main() {
final
RenderBox
renderObject
=
tester
.
renderObject
(
find
.
byType
(
ImageIcon
));
expect
(
renderObject
.
size
,
equals
(
const
Size
.
square
(
24.0
)));
});
testWidgets
(
'ImageIcon has semantics data'
,
(
WidgetTester
tester
)
async
{
final
SemanticsHandle
handle
=
tester
.
ensureSemantics
();
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
const
Center
(
child:
const
IconTheme
(
data:
const
IconThemeData
(),
child:
const
ImageIcon
(
null
,
semanticLabel:
'test'
)
),
),
),
);
expect
(
tester
.
getSemanticsData
(
find
.
byType
(
ImageIcon
)),
matchesSemanticsData
(
label:
'test'
,
textDirection:
TextDirection
.
ltr
,
));
handle
.
dispose
();
});
}
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