New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DecorationImage] adds scale property #54258
[DecorationImage] adds scale property #54258
Conversation
expect(error.toString(), contains('is not true')); | ||
return; | ||
} | ||
fail('DecorationImage didnot throw AssertionError when scale was null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail('DecorationImage didnot throw AssertionError when scale was null'); | |
fail('DecorationImage did not throw AssertionError when scale was null'); |
@@ -175,6 +183,7 @@ class DecorationImage { | |||
'$repeat', | |||
if (matchTextDirection) | |||
'match text direction', | |||
'$scale' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'$scale' | |
'scale: $scale' |
@@ -279,7 +279,7 @@ void main() { | |||
' direction provided in the ImageConfiguration object to match.\n' | |||
' The DecorationImage was:\n' | |||
' DecorationImage(SynchronousTestImageProvider(), center, match\n' | |||
' text direction)\n' | |||
' text direction, 1.0)\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's weird that it just says 1.0
. It should definitely say something like scale: 1.0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, the above change you suggested will resolve this. I'll do the changes.
@@ -129,6 +131,11 @@ class DecorationImage { | |||
/// in the top right. | |||
final bool matchTextDirection; | |||
|
|||
/// Defines image pixels to be shown per logical pixels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Defines image pixels to be shown per logical pixels | |
/// Defines image pixels to be shown per logical pixels. |
@@ -129,6 +131,11 @@ class DecorationImage { | |||
/// in the top right. | |||
final bool matchTextDirection; | |||
|
|||
/// Defines image pixels to be shown per logical pixels | |||
/// | |||
/// By default the the value of scale is 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// By default the the value of scale is 1.0 | |
/// By default, the value of scale is 1.0. |
@@ -583,4 +583,15 @@ void main() { | |||
expect(call.positionalArguments[2].center, outputRect.center); | |||
} | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also add a scale test similar to this paintImage scale test. The test in particular tests paintImage
, but you can combine elements from this BoxDecoration test with the scale test for paintImage
to achieve the outcome you need.
@@ -263,7 +272,7 @@ class DecorationImagePainter { | |||
canvas: canvas, | |||
rect: rect, | |||
image: _image.image, | |||
scale: _image.scale, | |||
scale: _details.scale, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems odd to me that we now completely ignore the scale of the actual image.
/cc @dnfield
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost certainly wrong, and unfortunately it doesn't look like we have a test covering it.
I would expect this to give you strange results if you now tried to use a DecorationImage
with an AssetImage
of a non-1.0 scale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnfield @goderbauer I understand the issue with this approach. It completely ignores the scale given to NetworkImage
and ExactAssetImage
.
But, if we are using scale property of ImageInfo
instead of DecorationImage
, we will have to create a new ImageProvider
before creating an ImageStream
, which means we would have to overwrite the scale of ImageInfo
with DecorationImage
, which we are doing in the current approach.
What if we document this behaviour in the API docs?
Also, let me know if there is a different approach that we can try here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we just multiplied the scale property from the decoration against the image scale, it should work out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add some tests that show that that works ok with and without this parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we should document this behavior - someone could then override it by wrapping the incoming provider with a new provider that sets the scale to 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnfield should I add a option to change the scale of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request is not suitable for automatic merging in its current state.
|
Description
Adds scale property to
DecorationImage
. The scale property is then passed topaintImage
function to scale the image.If users want to scale the
DecorationImage
they use the scale property now.Screenshot
Related Issues
#12452
Tests
I have added the test case to check assertion error for scale. To test the scale property is working properly or not, there are already test cases written for
paintImage
function.Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.