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
11678da3
Commit
11678da3
authored
Mar 06, 2019
by
Muhammed Salih Guler
Committed by
Jonah Williams
Mar 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add semantics label to FadeInImage. (#28799)
parent
0c7fe40e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
1 deletion
+141
-1
fade_in_image.dart
packages/flutter/lib/src/widgets/fade_in_image.dart
+53
-1
fade_in_image_test.dart
packages/flutter/test/widgets/fade_in_image_test.dart
+88
-0
No files found.
packages/flutter/lib/src/widgets/fade_in_image.dart
View file @
11678da3
...
...
@@ -66,10 +66,21 @@ class FadeInImage extends StatefulWidget {
/// The [placeholder], [image], [fadeOutDuration], [fadeOutCurve],
/// [fadeInDuration], [fadeInCurve], [alignment], [repeat], and
/// [matchTextDirection] arguments must not be null.
///
/// There are two different semantic label for the class.
/// [placeholderSemanticLabel] is used for defining a semantics label for
/// [placeholder]. [imageSemanticLabel] is used for defining a semantics label
/// for [image]
///
/// If [excludeFromSemantics] is true, then [placeholderSemanticLabel] and
/// [imageSemanticLabel] will be ignored.
const
FadeInImage
({
Key
key
,
@required
this
.
placeholder
,
@required
this
.
image
,
this
.
excludeFromSemantics
=
false
,
this
.
imageSemanticLabel
,
this
.
placeholderSemanticLabel
,
this
.
fadeOutDuration
=
const
Duration
(
milliseconds:
300
),
this
.
fadeOutCurve
=
Curves
.
easeOut
,
this
.
fadeInDuration
=
const
Duration
(
milliseconds:
700
),
...
...
@@ -118,6 +129,9 @@ class FadeInImage extends StatefulWidget {
@required
String
image
,
double
placeholderScale
=
1.0
,
double
imageScale
=
1.0
,
this
.
excludeFromSemantics
=
false
,
this
.
imageSemanticLabel
,
this
.
placeholderSemanticLabel
,
this
.
fadeOutDuration
=
const
Duration
(
milliseconds:
300
),
this
.
fadeOutCurve
=
Curves
.
easeOut
,
this
.
fadeInDuration
=
const
Duration
(
milliseconds:
700
),
...
...
@@ -174,6 +188,9 @@ class FadeInImage extends StatefulWidget {
AssetBundle
bundle
,
double
placeholderScale
,
double
imageScale
=
1.0
,
this
.
excludeFromSemantics
=
false
,
this
.
imageSemanticLabel
,
this
.
placeholderSemanticLabel
,
this
.
fadeOutDuration
=
const
Duration
(
milliseconds:
300
),
this
.
fadeOutCurve
=
Curves
.
easeOut
,
this
.
fadeInDuration
=
const
Duration
(
milliseconds:
700
),
...
...
@@ -284,6 +301,24 @@ class FadeInImage extends StatefulWidget {
/// scope.
final
bool
matchTextDirection
;
/// Whether to exclude this image from semantics.
///
/// Useful for images which do not contribute meaningful information to an
/// application.
final
bool
excludeFromSemantics
;
/// A Semantic description of the [placeholder].
///
/// Used to provide a description of the [placeholder] to TalkBack on Android, and
/// VoiceOver on iOS.
final
String
placeholderSemanticLabel
;
/// A Semantic description of the [image].
///
/// Used to provide a description of the [image] to TalkBack on Android, and
/// VoiceOver on iOS.
final
String
imageSemanticLabel
;
@override
State
<
StatefulWidget
>
createState
()
=>
_FadeInImageState
();
}
...
...
@@ -491,11 +526,17 @@ class _FadeInImageState extends State<FadeInImage> with TickerProviderStateMixin
:
_imageResolver
.
_imageInfo
;
}
String
get
_semanticLabel
{
return
_isShowingPlaceholder
?
widget
.
placeholderSemanticLabel
:
widget
.
imageSemanticLabel
;
}
@override
Widget
build
(
BuildContext
context
)
{
assert
(
_phase
!=
FadeInImagePhase
.
start
);
final
ImageInfo
imageInfo
=
_imageInfo
;
return
RawImage
(
final
RawImage
image
=
RawImage
(
image:
imageInfo
?.
image
,
width:
widget
.
width
,
height:
widget
.
height
,
...
...
@@ -507,6 +548,17 @@ class _FadeInImageState extends State<FadeInImage> with TickerProviderStateMixin
repeat:
widget
.
repeat
,
matchTextDirection:
widget
.
matchTextDirection
,
);
if
(
widget
.
excludeFromSemantics
)
{
return
image
;
}
return
Semantics
(
container:
_semanticLabel
!=
null
,
image:
true
,
label:
_semanticLabel
==
null
?
''
:
_semanticLabel
,
child:
image
,
);
}
@override
...
...
packages/flutter/test/widgets/fade_in_image_test.dart
View file @
11678da3
...
...
@@ -116,5 +116,93 @@ Future<void> main() async {
expect
(
displayedImage
().
image
,
isNot
(
same
(
placeholderImage
)));
// placeholder replaced
expect
(
displayedImage
().
image
,
same
(
secondPlaceholderImage
));
});
group
(
'semanticLabel'
,
()
{
const
String
placeholderSemanticText
=
'Test placeholder semantic label'
;
const
String
imageSemanticText
=
'Test image semantic label'
;
const
Duration
animationDuration
=
Duration
(
milliseconds:
50
);
testWidgets
(
'assigned correctly according to placeholder or image'
,
(
WidgetTester
tester
)
async
{
// The semantics widget that is created
Semantics
displayedWidget
()
=>
tester
.
widget
(
find
.
byType
(
Semantics
));
// The placeholder is expected to be already loaded
final
TestImageProvider
placeholderProvider
=
TestImageProvider
(
placeholderImage
);
// The image which takes long to load
final
TestImageProvider
imageProvider
=
TestImageProvider
(
targetImage
);
// Test case: Image and Placeholder semantic texts are provided.
await
tester
.
pumpWidget
(
FadeInImage
(
placeholder:
placeholderProvider
,
image:
imageProvider
,
fadeOutDuration:
animationDuration
,
fadeInDuration:
animationDuration
,
imageSemanticLabel:
imageSemanticText
,
placeholderSemanticLabel:
placeholderSemanticText
));
placeholderProvider
.
complete
();
// load the placeholder
await
tester
.
pump
();
expect
(
displayedWidget
().
properties
.
label
,
same
(
placeholderSemanticText
));
imageProvider
.
complete
();
// load the image
for
(
int
i
=
0
;
i
<
10
;
i
+=
1
)
{
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// do the fadeout and fade in
}
expect
(
displayedWidget
().
properties
.
label
,
same
(
imageSemanticText
));
});
testWidgets
(
'assigned correctly with only one semantics text'
,
(
WidgetTester
tester
)
async
{
// The semantics widget that is created
Semantics
displayedWidget
()
=>
tester
.
widget
(
find
.
byType
(
Semantics
));
// The placeholder is expected to be already loaded
final
TestImageProvider
placeholderProvider
=
TestImageProvider
(
placeholderImage
);
// The image which takes long to load
final
TestImageProvider
imageProvider
=
TestImageProvider
(
targetImage
);
// Test case: Placeholder semantic text provided.
await
tester
.
pumpWidget
(
FadeInImage
(
placeholder:
placeholderProvider
,
image:
imageProvider
,
fadeOutDuration:
animationDuration
,
fadeInDuration:
animationDuration
,
placeholderSemanticLabel:
placeholderSemanticText
));
placeholderProvider
.
complete
();
// load the placeholder
await
tester
.
pump
();
expect
(
displayedWidget
().
properties
.
label
,
same
(
placeholderSemanticText
));
imageProvider
.
complete
();
// load the image
for
(
int
i
=
0
;
i
<
10
;
i
+=
1
)
{
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// do the fadeout and fade in
}
expect
(
displayedWidget
().
properties
.
label
,
same
(
''
));
});
testWidgets
(
'assigned correctly without any semantics text'
,
(
WidgetTester
tester
)
async
{
// The semantics widget that is created
Semantics
displayedWidget
()
=>
tester
.
widget
(
find
.
byType
(
Semantics
));
// The placeholder is expected to be already loaded
final
TestImageProvider
placeholderProvider
=
TestImageProvider
(
placeholderImage
);
// The image which takes long to load
final
TestImageProvider
imageProvider
=
TestImageProvider
(
targetImage
);
// Test case: No semantic text provided.
await
tester
.
pumpWidget
(
FadeInImage
(
placeholder:
placeholderProvider
,
image:
imageProvider
,
fadeOutDuration:
animationDuration
,
fadeInDuration:
animationDuration
,
));
placeholderProvider
.
complete
();
// load the placeholder
await
tester
.
pump
();
expect
(
displayedWidget
().
properties
.
label
,
same
(
''
));
imageProvider
.
complete
();
// load the image
for
(
int
i
=
0
;
i
<
10
;
i
+=
1
)
{
await
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
// do the fadeout and fade in
}
expect
(
displayedWidget
().
properties
.
label
,
same
(
''
));
});
});
});
}
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