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
f800a67e
Unverified
Commit
f800a67e
authored
Sep 30, 2020
by
Pedro Massango
Committed by
GitHub
Sep 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] once errorBuilder is called Image widget stops loading images (#65180)
parent
e5de2b08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
image.dart
packages/flutter/lib/src/widgets/image.dart
+4
-0
image_test.dart
packages/flutter/test/widgets/image_test.dart
+60
-0
No files found.
packages/flutter/lib/src/widgets/image.dart
View file @
f800a67e
...
...
@@ -1184,6 +1184,8 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
setState
(()
{
_imageInfo
=
imageInfo
;
_loadingProgress
=
null
;
_lastException
=
null
;
_lastStack
=
null
;
_frameNumber
=
_frameNumber
==
null
?
0
:
_frameNumber
!
+
1
;
_wasSynchronouslyLoaded
=
_wasSynchronouslyLoaded
|
synchronousCall
;
});
...
...
@@ -1193,6 +1195,8 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
assert
(
widget
.
loadingBuilder
!=
null
);
setState
(()
{
_loadingProgress
=
event
;
_lastException
=
null
;
_lastStack
=
null
;
});
}
...
...
packages/flutter/test/widgets/image_test.dart
View file @
f800a67e
...
...
@@ -1762,6 +1762,52 @@ void main() {
debugOnPaintImage
=
null
;
});
testWidgets
(
'Load a good image after a bad image was loaded should not call errorBuilder'
,
(
WidgetTester
tester
)
async
{
final
UniqueKey
errorKey
=
UniqueKey
();
final
ui
.
Image
image
=
await
tester
.
runAsync
(()
=>
createTestImage
());
final
TestImageStreamCompleter
streamCompleter
=
TestImageStreamCompleter
();
final
TestImageProvider
imageProvider
=
TestImageProvider
(
streamCompleter:
streamCompleter
);
await
tester
.
pumpWidget
(
Center
(
child:
SizedBox
(
height:
50
,
width:
50
,
child:
Image
(
image:
imageProvider
,
excludeFromSemantics:
true
,
errorBuilder:
(
BuildContext
context
,
Object
error
,
StackTrace
stackTrace
)
{
return
Container
(
key:
errorKey
);
},
frameBuilder:
(
BuildContext
context
,
Widget
child
,
int
frame
,
bool
wasSynchronouslyLoaded
)
{
return
Padding
(
padding:
const
EdgeInsets
.
all
(
1
),
child:
child
);
},
),
),
),
);
// No error widget before loading a invalid image.
expect
(
find
.
byKey
(
errorKey
),
findsNothing
);
// Loading good image succeed
streamCompleter
.
setData
(
chunkEvent:
const
ImageChunkEvent
(
cumulativeBytesLoaded:
10
,
expectedTotalBytes:
100
));
await
tester
.
pump
();
expect
(
find
.
byType
(
Padding
),
findsOneWidget
);
// Loading bad image shows the error widget.
streamCompleter
.
setError
(
exception:
'thrown'
);
await
tester
.
pump
();
expect
(
find
.
byKey
(
errorKey
),
findsOneWidget
);
// Loading good image shows the image widget instead of the error widget.
streamCompleter
.
setData
(
imageInfo:
ImageInfo
(
image:
image
));
await
tester
.
pump
();
expect
(
find
.
byType
(
Padding
),
findsOneWidget
);
expect
(
tester
.
widget
<
Padding
>(
find
.
byType
(
Padding
)).
child
,
isA
<
RawImage
>());
expect
(
find
.
byKey
(
errorKey
),
findsNothing
);
});
}
class
ImagePainter
extends
CustomPainter
{
...
...
@@ -1889,6 +1935,20 @@ class TestImageStreamCompleter extends ImageStreamCompleter {
}
}
}
void
setError
({
dynamic
exception
,
StackTrace
stackTrace
,
})
{
assert
(
exception
!=
null
,
'exception must not be null.'
);
final
List
<
ImageStreamListener
>
localListeners
=
listeners
.
toList
();
for
(
final
ImageStreamListener
listener
in
localListeners
)
{
if
(
listener
.
onError
!=
null
)
{
listener
.
onError
(
exception
,
stackTrace
);
}
}
}
}
class
DebouncingImageProvider
extends
ImageProvider
<
Object
>
{
...
...
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