Skip to content

Image.asset determines scale of asset based on whether path contains 3.0x #17241

Closed

Description

@fmatosqg
  • Actual behavior: whenever a path to a file contains "3.0x" it will be displayed as a xxhdpi (3x) high resolution image
  • Expected behavior: must pay close attention to what the app developer specified in pubspec.yaml. Not doing so may compromise introducing other kinds of variants in the future.

Sample pubspec.yaml

. . .
  assets:
    - assets/3.0x/ic_accessibility_black_36dp.png 
    - assets/3.0x/yetAnotherFolder/hackyAsset.png

When loading such images with

new Image.asset('assets/3.0x/yetAnotherFolder/hackyAsset.png'),

or

 new Image.asset('assets/3.0x/ic_accessibility_black_36dp.png'),
  • expected behavior: They should behave like mdpi (1x) images
  • actual behavior: They behave like xxhdpi (3x) hi-res image

There are 2 pitfalls here. The obvious one is that path assets/3.0x/yetAnotherFolder doesn't comply with the specs that the main file sits on <folder> and the variant sits on <folder>/3.0x. The second is that the intention of the app developer may have been putting a mdpi (1x) file on assets/3.0x/ic_accessibility_black_36dp.png .

I like how smart it is, but a) this is clashing with what AssetManifest.json says. And b) I'm afraid that one day other types of variants (say screen size, localization...) will make pre-existing apps break because they'll start treating its main variant assets as non-main variants. In any case I can't be sure if this is a feature or a bug. I'd like to help document it properly if it's the former or fix it if it's the latter.

@tvolkert @Hixie @HansMuller

Activity

  1. fmatosqg commented on May 3, 2018

    @fmatosqg
    ContributorAuthor

    Inspecting pubspec.yaml for flutter gallery I got a bit more confused:

    flutter:
      uses-material-design: true
      assets:
        - lib/gallery/example_code.dart
        - packages/flutter_gallery_assets/white_logo/logo.png
        - packages/flutter_gallery_assets/white_logo/1.5x/logo.png
        - packages/flutter_gallery_assets/white_logo/2.5x/logo.png
        - packages/flutter_gallery_assets/white_logo/3.0x/logo.png
        - packages/flutter_gallery_assets/white_logo/4.0x/logo.png
        - packages/flutter_gallery_assets/videos/butterfly.mp4
        - packages/flutter_gallery_assets/animated_flutter_lgtm.gif
    . . .
    

    I would expect this

    flutter:
      uses-material-design: true
      assets:
        - lib/gallery/example_code.dart
        - packages/flutter_gallery_assets/white_logo/logo.png
        - packages/flutter_gallery_assets/videos/butterfly.mp4
        - packages/flutter_gallery_assets/animated_flutter_lgtm.gif
    . . .
    
  2. tvolkert commented on May 3, 2018

    @tvolkert
    Contributor

    Yeah me too. @HansMuller do the variants need to be explicitly listed?

  3. fmatosqg commented on May 4, 2018

    @fmatosqg
    ContributorAuthor

    I'm terribly bad at regular expressions or else I'd already have changed it in image_resolution.dart. Anyway, the new unit tests included in above commit should be a good conversation started to get everybody on the same page on this problem.

    Also removed puzzling lines from gallery's pubspec, I built app and it's still working.

  4. HansMuller commented on May 4, 2018

    @HansMuller
    Contributor

    @fmatosqg you are correct about the white_logo gallery asset variants. Sorry about that, my fault.

  5. fmatosqg commented on May 5, 2018

    @fmatosqg
    ContributorAuthor

    @HansMuller as long as we're in the business of problem solving (not blame assigning) that's just a hiccup :)

    I'm still not confident I understand all the intentions behind asset image ratios but I tried to enforce my own understanding of it with unit tests and a small fix on #17322. I'd suggest reading the comments before the code, I hope the clarification is clear enough (no pun intended)

  6. tvolkert commented on May 29, 2018

    @tvolkert
    Contributor

    It looks like this was closed by #17322 - feel free to re-open if there's more to do here.

  7. fmatosqg commented on May 29, 2018

    @fmatosqg
    ContributorAuthor

    That's right, #17322 completely covers this issue.

  8. added 2 commits that reference this issue on Mar 24, 2020
  9. added a commit that references this issue on Mar 25, 2020
  10. github-actions commented on Sep 3, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions