Skip to content

Example code for adding an image doesn't actually show the image #9901

Closed

Description

@goderbauer

I just learnt how to add an image to my app from https://flutter.io/assets-and-images/.

After pasting the example code from the "Loading images" section into my app, the app didn't actually show an image (I think I now understand why that is). It might be more useful/satisfying to include code in the example that actually shows the image when copied to get people started quicker. I ended up using new Image.asset('assets/sunset.jpg') to verify that the image would actually load in my app.

Activity

  1. goderbauer commented on May 8, 2017

    @goderbauer
    MemberAuthor

    This is what my build method looks like:

      @override
      Widget build(BuildContext context) {
        return new Image.asset('assets/sunset2.jpg');
      }
  2. HansMuller commented on May 9, 2017

    @HansMuller
    Contributor

    Perhaps if the assets-and-images section pointed at a small working "sample app" in addition to providing code fragments, you'd have had less trouble (#9912).

  3. LarkAscending commented on Jun 3, 2017

    @LarkAscending

    Talking w/ @goderbauer root cause is the parent of the Image widget needs to actually have a size in order to display the image. So the code snippet for the build() method needs to include a parent-with-size.

  4. Hixie commented on Jun 4, 2017

    @Hixie
    Contributor

    The Image widget should size itself to the size of the image by default.

  5. zoechi commented on Dec 3, 2018

    @zoechi
    Contributor

    Issue moved to flutter/website #1826 via ZenHub

  6. github-actions commented on Sep 1, 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.

  7. locked as resolved and limited conversation to collaborators on Sep 1, 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