skip to Main Content

I am trying to make an Image have a fixed width but the height should be auto. More like a responsive image.

Here is the code I wrote but it is not working

Image.file(
   imageFile!,
   height: auto,
   width: 200,
),

2

Answers


  1. Just don’t provide height and leave it like this:

    Image.file(
       imageFile!,
       width: 200,
    ),
    

    Flutter will automatically adjust the height for you

    Login or Signup to reply.
  2. i suggest the next:

    Container(
    width : 200,
    child: Image.asset(
      'You Image',
       width : 200,
       fit: BoxFit.fitWidth,
     )
    )
    

    Don’t impose any constraints on height, so it’s freely changes its height while having a fixed width.

    The height will depend on the main dimensions of the image.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search