Skip to content

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

Closed

Description

@zoechi

@goderbauer commented on Tue May 09 2017

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.


@goderbauer commented on Tue May 09 2017

This is what my build method looks like:

  @override
  Widget build(BuildContext context) {
    return new Image.asset('assets/sunset2.jpg');
  }

@HansMuller commented on Tue May 09 2017

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 (flutter/flutter#9912).


@LarkAscending commented on Sat Jun 03 2017

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.


@Hixie commented on Sun Jun 04 2017

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

Activity

  1. added
    p2-mediumNecessary but not urgent concern. Resolve when possible.
    on Jun 10, 2019
  2. micpap25 commented on Sep 1, 2021

    @micpap25
    Contributor

    Can this be closed? I'm pretty sure the merged PR fixes this.

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

    e1-hoursEffort: < 8 hrsp2-mediumNecessary but not urgent concern. Resolve when possible.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions