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

Make default scale value null so that Flutter decides the one to use #247

Merged
merged 2 commits into from
Jun 8, 2022

Conversation

davidmigloz
Copy link
Contributor

If you have an image with different resolution variants:

assets/images/myImage.png
assets/images/2.0x/myImage.png
assets/images/3.0x/myImage.png

At the moment, if you use the generated image() method with the default parameters. Eg:

Assets.images.myImage.image()

It will always use assets/images/myImage.png independently of the pixel ratio of the device. This happens because the default parameter of scale is 1.0:

Image image({
    Key? key,
    AssetBundle? bundle,
    ImageFrameBuilder? frameBuilder,
    ImageErrorWidgetBuilder? errorBuilder,
    String? semanticLabel,
    bool excludeFromSemantics = false,
    double? scale = 1.0, // <-- THIS
    //...
})

To workaround this issue at the moment you always have to set scale to null:

Assets.images.myImage.image(scale: null)

Proposed fix:
I believe the default value of scale should not be 1.0 but null as it is in the Flutter's Image.asset constructor.

@davidmigloz davidmigloz closed this Jun 2, 2022
@wasabeef wasabeef reopened this Jun 3, 2022
@wasabeef wasabeef added this to the 4.2.2 milestone Jun 3, 2022
@wasabeef wasabeef self-requested a review June 3, 2022 08:10
@wasabeef
Copy link
Member

wasabeef commented Jun 3, 2022

@davidmigloz

As you said, I'd like to merge this PR.

@davidmigloz
Copy link
Contributor Author

Perfect!

(Sorry, I closed the ticket by mistake)

@vietstone-ng
Copy link

This is nice. How can I use this pr before it get merged and released?

@wasabeef
Copy link
Member

wasabeef commented Jun 7, 2022

@davidmigloz @vietstone-ng
I will release the next version that included until tomorrow.

@wasabeef wasabeef merged commit 512943d into FlutterGen:main Jun 8, 2022
@wasabeef wasabeef mentioned this pull request Jun 9, 2022
@wasabeef
Copy link
Member

wasabeef commented Jun 9, 2022

@davidmigloz @vietstone-ng
Hi, just released v4.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants