Skip to content
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

Merged
merged 4 commits into from Apr 18, 2020
Merged

[DecorationImage] adds scale property #54258

merged 4 commits into from Apr 18, 2020

Conversation

AyushBherwani1998
Copy link
Member

@AyushBherwani1998 AyushBherwani1998 commented Apr 8, 2020

Description

Adds scale property to DecorationImage. The scale property is then passed to paintImage 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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 8, 2020
expect(error.toString(), contains('is not true'));
return;
}
fail('DecorationImage didnot throw AssertionError when scale was null');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'$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'
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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);
}
});

Copy link
Contributor

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,
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnfield I'll do the required changes. I'll add the test which shows that it works properly with scale property. We already have test cases which don't use scale property, example

@AyushBherwani1998
Copy link
Member Author

@dnfield should I add a option to change the scale of SynchronousTestImageProvider? It will give us a more accurate test. WDYT?

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite hostonly_devicelab_tests-0-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot merged commit f35b673 into flutter:master Apr 18, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants