Skip to content

Image Widget: Displaying Image.asset with an explicit scale does not work #18679

Closed

Description

@sir-boformer

Example application: https://github.com/sir-boformer/flutter_image_bugs/blob/master/lib/main.dart


When I try to load an image variant with an explicit scale, Flutter always gets the default 1.0x variant:

new Image.asset('images/test.png', scale: 3.0, width: 48.0, height: 48.0)

The automatic variant selection (scale: null) works correctly:

new Image.asset('images/test.png', width: 48.0, height: 48.0)

screenshot_1529596875

Activity

  1. zoechi commented on Jun 22, 2018

    @zoechi
    Contributor

    Please add the output of flutter doctor

  2. sir-boformer commented on Jun 22, 2018

    @sir-boformer
    ContributorAuthor

    @zoechi I also just tested this with a real Android device with a pixel ratio of 2.0, same problem occurs

    [√] Flutter (Channel master, v0.5.6-pre.20, on Microsoft Windows [Version 10.0.17134.112], locale de-DE)
        • Flutter version 0.5.6-pre.20 at C:\flutter
        • Framework revision 3f79f8cba5 (6 days ago), 2018-06-16 12:54:02 -0700
        • Engine revision c3976b3c71
        • Dart version 2.0.0-dev.61.0.flutter-c95617b19c
    
    [√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
        • Android SDK at C:\Users\Felix\AppData\Local\Android\sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-27, build-tools 27.0.3
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
        • All Android licenses accepted.
    
    [√] Android Studio (version 3.1)
        • Android Studio at C:\Program Files\Android\Android Studio
        • Flutter plugin version 25.0.1
        • Dart plugin version 173.4700
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    
    [!] VS Code, 64-bit edition (version 1.24.1)
        • VS Code at C:\Program Files\Microsoft VS Code
        • Flutter extension not installed; install from
          https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    
    [√] Connected devices (1 available)
        • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.0.0 (API 26) (emulator)
    
  3. zoechi commented on Jun 22, 2018

    @zoechi
    Contributor
  4. sir-boformer commented on Jun 22, 2018

    @sir-boformer
    ContributorAuthor

    I'm not sure if the tag you set is correct. This is a problem of the core framework.

  5. added
    engineflutter/engine related. See also e: labels.
    on Jun 22, 2018
  6. zoechi commented on Jun 22, 2018

    @zoechi
    Contributor

    I wasn't sure. Could be a simple copy-paste error in AssetImage or a serious issue in the engine.
    I added engine

  7. sir-boformer commented on Aug 29, 2018

    @sir-boformer
    ContributorAuthor

    Looking at this again, there is a simple workaround. Could be the intended behaviour.

    Instead of:

    new Image.asset('images/test.png', scale: 2.0, width: 48.0, height: 48.0)

    just write:

    new Image.asset('images/2.0x/test.png', scale: 2.0, width: 48.0, height: 48.0)

    And everything will work correctly. Flutter just uses the image path as-is when you set an explicit scale.


    This should be mentioned explicitly in the documentation.

  8. added a commit that references this issue on Aug 29, 2018
    89867cf
  9. added a commit that references this issue on Sep 18, 2018
    3c22d7b
  10. github-actions commented on Sep 2, 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 2, 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

    engineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions