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
35b55d51
Unverified
Commit
35b55d51
authored
Jul 31, 2018
by
xster
Committed by
GitHub
Jul 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add image stream error handling mechanism (#18424)
parent
e9c8e36b
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
756 additions
and
294 deletions
+756
-294
image_stream.dart
packages/flutter/lib/src/painting/image_stream.dart
+147
-48
image.dart
packages/flutter/lib/src/widgets/image.dart
+24
-3
image_stream_test.dart
packages/flutter/test/painting/image_stream_test.dart
+274
-240
image_test.dart
packages/flutter/test/widgets/image_test.dart
+311
-3
No files found.
packages/flutter/lib/src/painting/image_stream.dart
View file @
35b55d51
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/widgets/image.dart
View file @
35b55d51
...
@@ -55,7 +55,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
...
@@ -55,7 +55,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
/// Prefetches an image into the image cache.
/// Prefetches an image into the image cache.
///
///
/// Returns a [Future] that will complete when the first image yielded by the
/// Returns a [Future] that will complete when the first image yielded by the
/// [ImageProvider] is available.
/// [ImageProvider] is available
or failed to load
.
///
///
/// If the image is later used by an [Image] or [BoxDecoration] or [FadeInImage],
/// If the image is later used by an [Image] or [BoxDecoration] or [FadeInImage],
/// it will probably be loaded faster. The consumer of the image does not need
/// it will probably be loaded faster. The consumer of the image does not need
...
@@ -65,17 +65,38 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
...
@@ -65,17 +65,38 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size si
/// The [BuildContext] and [Size] are used to select an image configuration
/// The [BuildContext] and [Size] are used to select an image configuration
/// (see [createLocalImageConfiguration]).
/// (see [createLocalImageConfiguration]).
///
///
/// The `onError` argument can be used to manually handle errors while precaching.
///
/// See also:
/// See also:
///
///
/// * [ImageCache], which holds images that may be reused.
/// * [ImageCache], which holds images that may be reused.
Future
<
Null
>
precacheImage
(
ImageProvider
provider
,
BuildContext
context
,
{
Size
size
})
{
Future
<
Null
>
precacheImage
(
ImageProvider
provider
,
BuildContext
context
,
{
Size
size
,
ImageErrorListener
onError
,
})
{
final
ImageConfiguration
config
=
createLocalImageConfiguration
(
context
,
size:
size
);
final
ImageConfiguration
config
=
createLocalImageConfiguration
(
context
,
size:
size
);
final
Completer
<
Null
>
completer
=
new
Completer
<
Null
>();
final
Completer
<
Null
>
completer
=
new
Completer
<
Null
>();
final
ImageStream
stream
=
provider
.
resolve
(
config
);
final
ImageStream
stream
=
provider
.
resolve
(
config
);
void
listener
(
ImageInfo
image
,
bool
sync
)
{
void
listener
(
ImageInfo
image
,
bool
sync
)
{
completer
.
complete
();
completer
.
complete
();
}
}
stream
.
addListener
(
listener
);
void
errorListener
(
dynamic
exception
,
StackTrace
stackTrace
)
{
completer
.
complete
();
if
(
onError
!=
null
)
{
onError
(
exception
,
stackTrace
);
}
else
{
FlutterError
.
reportError
(
new
FlutterErrorDetails
(
context:
'image failed to precache'
,
library
:
'image resource service'
,
exception:
exception
,
stack:
stackTrace
,
silent:
true
,
));
}
}
stream
.
addListener
(
listener
,
onError:
errorListener
);
completer
.
future
.
then
((
Null
_
)
{
stream
.
removeListener
(
listener
);
});
completer
.
future
.
then
((
Null
_
)
{
stream
.
removeListener
(
listener
);
});
return
completer
.
future
;
return
completer
.
future
;
}
}
...
...
packages/flutter/test/painting/image_stream_test.dart
View file @
35b55d51
This diff is collapsed.
Click to expand it.
packages/flutter/test/widgets/image_test.dart
View file @
35b55d51
This diff is collapsed.
Click to expand it.
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