2

I created a horizontal ListView contains lots of images, but each image in ListView does not fit the screen (sometimes I have to scroll to see the rest of it and of course a part of the next image). How can I stretch each image fit the screen and scroll to see the next image (next image has to fit the screen too)

UPDATE EXAMPLE Horizontal Image ListView

4 Answers 4

1

You can use DecorationImage with BoxFit.fill

Example:

Container(
          width: 64.0,
          height: 64.0,
          decoration: new BoxDecoration(
            shape: BoxShape.circle,
            image: new DecorationImage(
                fit: BoxFit.fill,
                image: new NetworkImage('my_url.jpg')
            )
        )) 
Sign up to request clarification or add additional context in comments.

4 Comments

No, I mean stretch each image in horizontal ListView to screen not just single image
Can you have a mockup or screenshot. I don't know what do you mean?
Updated example
So I think you can set the width of image equal screen size. To get the width of screensize. You can use ``` MediaQuery.of(context).size.width, ```
1

What I meant was carousel widget, never heard about it before. I was new at Mobile development.

Comments

0

You can use this code for Horizontal list view with perfect fit images.

 Container(
            height: 275,
            child: ListView.builder(
              scrollDirection: Axis.horizontal,
              shrinkWrap: true,
              itemCount: furnitures.length,
              itemBuilder: (BuildContext context, int index) {
                Map furniture = furnitures[index];

                return Padding(
                  padding: EdgeInsets.only(right: 20),
                  child: GestureDetector(
                    onTap: (){
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (BuildContext context){
                            return Details();
                          },
                        ),
                      );
                    },
                    child: Container(
                      height: 275,
                      width: 280,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            furniture['name'],
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 20,
                            ),
                          ),
                          SizedBox(height: 10),
                          ClipRRect(
                            borderRadius: BorderRadius.circular(15),
                            child: Image.asset(
                              "${furniture["img"]}",
                              height: 240,
                              width: 280,
                              fit: BoxFit.cover,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                );
              },

            ),
          )

Comments

0

You can use MediaQuery to achieve this. Simply by typing MediaQuery.of(context).size.width which gives you the width of the device screen then you assign to the width of the image

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.