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
3ee473c5
Unverified
Commit
3ee473c5
authored
Jan 14, 2019
by
Ian Hickson
Committed by
GitHub
Jan 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make decodeImageFromList mockable (#25864)
parent
78f4878f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
6 deletions
+21
-6
image_decoder.dart
packages/flutter/lib/src/painting/image_decoder.dart
+14
-5
image_decoder_test.dart
packages/flutter/test/painting/image_decoder_test.dart
+5
-1
box_decoration_test.dart
packages/flutter/test/widgets/box_decoration_test.dart
+1
-0
shape_decoration_test.dart
packages/flutter/test/widgets/shape_decoration_test.dart
+1
-0
No files found.
packages/flutter/lib/src/painting/image_decoder.dart
View file @
3ee473c5
...
...
@@ -4,15 +4,24 @@
import
'dart:async'
;
import
'dart:typed_data'
;
import
'dart:ui'
as
ui
show
Image
,
decodeImageFromList
;
import
'dart:ui'
as
ui
show
Codec
,
FrameInfo
,
Image
;
import
'binding.dart'
;
/// Creates an image from a list of bytes.
///
/// This function attempts to interpret the given bytes an image. If successful,
/// the returned [Future] resolves to the decoded image. Otherwise, the [Future]
/// resolves to null.
Future
<
ui
.
Image
>
decodeImageFromList
(
Uint8List
list
)
{
final
Completer
<
ui
.
Image
>
completer
=
Completer
<
ui
.
Image
>();
ui
.
decodeImageFromList
(
list
,
completer
.
complete
);
return
completer
.
future
;
///
/// If the image is animated, this returns the first frame. Consider
/// [instantiateImageCodec] if support for animated images is necessary.
///
/// This function differs from [ui.decodeImageFromList] in that it defers to
/// [PaintingBinding.instantiateImageCodec], and therefore can be mocked in
/// tests.
Future
<
ui
.
Image
>
decodeImageFromList
(
Uint8List
bytes
)
async
{
final
ui
.
Codec
codec
=
await
PaintingBinding
.
instance
.
instantiateImageCodec
(
bytes
);
final
ui
.
FrameInfo
frameInfo
=
await
codec
.
getNextFrame
();
return
frameInfo
.
image
;
}
packages/flutter/test/painting/image_decoder_test.dart
View file @
3ee473c5
...
...
@@ -6,15 +6,19 @@ import 'dart:typed_data';
import
'dart:ui'
as
ui
;
import
'package:flutter/painting.dart'
;
import
'../flutter_test_alternative.dart'
;
import
'../flutter_test_alternative.dart'
;
import
'binding_test.dart'
;
import
'image_data.dart'
;
void
main
(
)
{
final
PaintingBindingSpy
binding
=
PaintingBindingSpy
();
test
(
'Image decoder control test'
,
()
async
{
expect
(
binding
.
instantiateImageCodecCalledCount
,
0
);
final
ui
.
Image
image
=
await
decodeImageFromList
(
Uint8List
.
fromList
(
kTransparentImage
));
expect
(
image
,
isNotNull
);
expect
(
image
.
width
,
1
);
expect
(
image
.
height
,
1
);
expect
(
binding
.
instantiateImageCodecCalledCount
,
1
);
});
}
packages/flutter/test/widgets/box_decoration_test.dart
View file @
3ee473c5
...
...
@@ -36,6 +36,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
}
Future
<
void
>
main
()
async
{
AutomatedTestWidgetsFlutterBinding
();
TestImageProvider
.
image
=
await
decodeImageFromList
(
Uint8List
.
fromList
(
kTransparentImage
));
testWidgets
(
'DecoratedBox handles loading images'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/widgets/shape_decoration_test.dart
View file @
3ee473c5
...
...
@@ -14,6 +14,7 @@ import '../rendering/mock_canvas.dart';
import
'test_border.dart'
show
TestBorder
;
Future
<
void
>
main
()
async
{
AutomatedTestWidgetsFlutterBinding
();
final
ui
.
Image
rawImage
=
await
decodeImageFromList
(
Uint8List
.
fromList
(
kTransparentImage
));
final
ImageProvider
image
=
TestImageProvider
(
0
,
0
,
image:
rawImage
);
testWidgets
(
'ShapeDecoration.image'
,
(
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