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
f35b673f
Unverified
Commit
f35b673f
authored
Apr 18, 2020
by
Ayush Bherwani
Committed by
GitHub
Apr 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DecorationImage] adds scale property (#54258)
parent
55cbf804
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
decoration_image.dart
packages/flutter/lib/src/painting/decoration_image.dart
+14
-4
decoration_test.dart
packages/flutter/test/painting/decoration_test.dart
+31
-1
No files found.
packages/flutter/lib/src/painting/decoration_image.dart
View file @
f35b673f
...
@@ -47,10 +47,12 @@ class DecorationImage {
...
@@ -47,10 +47,12 @@ class DecorationImage {
this
.
centerSlice
,
this
.
centerSlice
,
this
.
repeat
=
ImageRepeat
.
noRepeat
,
this
.
repeat
=
ImageRepeat
.
noRepeat
,
this
.
matchTextDirection
=
false
,
this
.
matchTextDirection
=
false
,
this
.
scale
=
1.0
})
:
assert
(
image
!=
null
),
})
:
assert
(
image
!=
null
),
assert
(
alignment
!=
null
),
assert
(
alignment
!=
null
),
assert
(
repeat
!=
null
),
assert
(
repeat
!=
null
),
assert
(
matchTextDirection
!=
null
);
assert
(
matchTextDirection
!=
null
),
assert
(
scale
!=
null
);
/// The image to be painted into the decoration.
/// The image to be painted into the decoration.
///
///
...
@@ -129,6 +131,12 @@ class DecorationImage {
...
@@ -129,6 +131,12 @@ class DecorationImage {
/// in the top right.
/// in the top right.
final
bool
matchTextDirection
;
final
bool
matchTextDirection
;
/// Defines image pixels to be shown per logical pixels.
///
/// By default the the value of scale is 1.0. The scale for the image is
/// calculated by multiplying [scale] with `scale` of the given [ImageProvider].
final
double
scale
;
/// Creates a [DecorationImagePainter] for this [DecorationImage].
/// Creates a [DecorationImagePainter] for this [DecorationImage].
///
///
/// The `onChanged` argument must not be null. It will be called whenever the
/// The `onChanged` argument must not be null. It will be called whenever the
...
@@ -152,11 +160,12 @@ class DecorationImage {
...
@@ -152,11 +160,12 @@ class DecorationImage {
&&
other
.
alignment
==
alignment
&&
other
.
alignment
==
alignment
&&
other
.
centerSlice
==
centerSlice
&&
other
.
centerSlice
==
centerSlice
&&
other
.
repeat
==
repeat
&&
other
.
repeat
==
repeat
&&
other
.
matchTextDirection
==
matchTextDirection
;
&&
other
.
matchTextDirection
==
matchTextDirection
&&
other
.
scale
==
scale
;
}
}
@override
@override
int
get
hashCode
=>
hashValues
(
image
,
colorFilter
,
fit
,
alignment
,
centerSlice
,
repeat
,
matchTextDirection
);
int
get
hashCode
=>
hashValues
(
image
,
colorFilter
,
fit
,
alignment
,
centerSlice
,
repeat
,
matchTextDirection
,
scale
);
@override
@override
String
toString
()
{
String
toString
()
{
...
@@ -175,6 +184,7 @@ class DecorationImage {
...
@@ -175,6 +184,7 @@ class DecorationImage {
'
$repeat
'
,
'
$repeat
'
,
if
(
matchTextDirection
)
if
(
matchTextDirection
)
'match text direction'
,
'match text direction'
,
'scale:
$scale
'
];
];
return
'
${objectRuntimeType(this, 'DecorationImage')}
(
${properties.join(", ")}
)'
;
return
'
${objectRuntimeType(this, 'DecorationImage')}
(
${properties.join(", ")}
)'
;
}
}
...
@@ -263,7 +273,7 @@ class DecorationImagePainter {
...
@@ -263,7 +273,7 @@ class DecorationImagePainter {
canvas:
canvas
,
canvas:
canvas
,
rect:
rect
,
rect:
rect
,
image:
_image
.
image
,
image:
_image
.
image
,
scale:
_image
.
scale
,
scale:
_
details
.
scale
*
_
image
.
scale
,
colorFilter:
_details
.
colorFilter
,
colorFilter:
_details
.
colorFilter
,
fit:
_details
.
fit
,
fit:
_details
.
fit
,
alignment:
_details
.
alignment
.
resolve
(
configuration
.
textDirection
),
alignment:
_details
.
alignment
.
resolve
(
configuration
.
textDirection
),
...
...
packages/flutter/test/painting/decoration_test.dart
View file @
f35b673f
...
@@ -279,7 +279,7 @@ void main() {
...
@@ -279,7 +279,7 @@ void main() {
' direction provided in the ImageConfiguration object to match.
\n
'
' direction provided in the ImageConfiguration object to match.
\n
'
' The DecorationImage was:
\n
'
' The DecorationImage was:
\n
'
' DecorationImage(SynchronousTestImageProvider(), center, match
\n
'
' DecorationImage(SynchronousTestImageProvider(), center, match
\n
'
' text direction)
\n
'
' text direction
, scale: 1.0
)
\n
'
' The ImageConfiguration was:
\n
'
' The ImageConfiguration was:
\n
'
' ImageConfiguration(size: Size(100.0, 100.0))
\n
'
' ImageConfiguration(size: Size(100.0, 100.0))
\n
'
);
);
...
@@ -583,4 +583,34 @@ void main() {
...
@@ -583,4 +583,34 @@ void main() {
expect
(
call
.
positionalArguments
[
2
].
center
,
outputRect
.
center
);
expect
(
call
.
positionalArguments
[
2
].
center
,
outputRect
.
center
);
}
}
});
});
test
(
'scale cannot be null in DecorationImage'
,
()
{
try
{
DecorationImage
(
scale:
null
,
image:
SynchronousTestImageProvider
());
}
on
AssertionError
catch
(
error
)
{
expect
(
error
.
toString
(),
contains
(
'scale != null'
));
expect
(
error
.
toString
(),
contains
(
'is not true'
));
return
;
}
fail
(
'DecorationImage did not throw AssertionError when scale was null'
);
});
test
(
'DecorationImage scale test'
,
()
{
final
DecorationImage
backgroundImage
=
DecorationImage
(
image:
SynchronousTestImageProvider
(),
scale:
4
,
alignment:
Alignment
.
topLeft
);
final
BoxDecoration
boxDecoration
=
BoxDecoration
(
image:
backgroundImage
);
final
BoxPainter
boxPainter
=
boxDecoration
.
createBoxPainter
(()
{
assert
(
false
);
});
final
TestCanvas
canvas
=
TestCanvas
(<
Invocation
>[]);
boxPainter
.
paint
(
canvas
,
Offset
.
zero
,
const
ImageConfiguration
(
size:
Size
(
100.0
,
100.0
)));
final
Invocation
call
=
canvas
.
invocations
.
firstWhere
((
Invocation
call
)
=>
call
.
memberName
==
#drawImageRect
);
// The image should scale down to Size(25.0, 25.0) from Size(100.0, 100.0)
// considering DecorationImage scale to be 4.0 and Image scale to be 1.0.
expect
(
call
.
positionalArguments
[
2
].
size
,
const
Size
(
25.0
,
25.0
));
expect
(
call
.
positionalArguments
[
2
],
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
25.0
,
25.0
));
});
}
}
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