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
8735ab1e
Unverified
Commit
8735ab1e
authored
Feb 07, 2020
by
Dan Field
Committed by
GitHub
Feb 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make onImage re-entrant safe (#50316)
parent
7b074468
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
image.dart
packages/flutter/lib/src/widgets/image.dart
+6
-2
image_test.dart
packages/flutter/test/widgets/image_test.dart
+9
-5
No files found.
packages/flutter/lib/src/widgets/image.dart
View file @
8735ab1e
...
@@ -88,11 +88,15 @@ Future<void> precacheImage(
...
@@ -88,11 +88,15 @@ Future<void> precacheImage(
ImageStreamListener
listener
;
ImageStreamListener
listener
;
listener
=
ImageStreamListener
(
listener
=
ImageStreamListener
(
(
ImageInfo
image
,
bool
sync
)
{
(
ImageInfo
image
,
bool
sync
)
{
completer
.
complete
();
if
(!
completer
.
isCompleted
)
{
completer
.
complete
();
}
stream
.
removeListener
(
listener
);
stream
.
removeListener
(
listener
);
},
},
onError:
(
dynamic
exception
,
StackTrace
stackTrace
)
{
onError:
(
dynamic
exception
,
StackTrace
stackTrace
)
{
completer
.
complete
();
if
(!
completer
.
isCompleted
)
{
completer
.
complete
();
}
stream
.
removeListener
(
listener
);
stream
.
removeListener
(
listener
);
if
(
onError
!=
null
)
{
if
(
onError
!=
null
)
{
onError
(
exception
,
stackTrace
);
onError
(
exception
,
stackTrace
);
...
...
packages/flutter/test/widgets/image_test.dart
View file @
8735ab1e
...
@@ -639,13 +639,17 @@ void main() {
...
@@ -639,13 +639,17 @@ void main() {
)
)
);
);
expect
(
imageStreamCompleter
.
listeners
.
length
,
2
);
// Two listeners - one is the listener added by precacheImage, the other by the ImageCache.
imageStreamCompleter
.
listeners
.
toList
()[
1
].
onImage
(
null
,
null
);
final
List
<
ImageStreamListener
>
listeners
=
imageStreamCompleter
.
listeners
.
toList
();
expect
(
listeners
.
length
,
2
);
expect
(
imageStreamCompleter
.
listeners
.
length
,
1
);
// Make sure the first listener can be called re-entrantly
imageStreamCompleter
.
listeners
.
toList
()[
0
].
onImage
(
null
,
null
);
listeners
[
1
].
onImage
(
null
,
null
);
listeners
[
1
].
onImage
(
null
,
null
);
expect
(
imageStreamCompleter
.
listeners
.
length
,
0
);
// Make sure the second listener can be called re-entrantly.
listeners
[
0
].
onImage
(
null
,
null
);
listeners
[
0
].
onImage
(
null
,
null
);
});
});
testWidgets
(
'Precache completes with onError on error'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Precache completes with onError on error'
,
(
WidgetTester
tester
)
async
{
...
...
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