flutterimagestretchfitted-box

Expanded in SingleChildScrollView crashes the application


I'm trying to make an application on Flutter. I ran into a problem: I can't make the images stretch in width.

I need 2 columns, each has an image, each column should be 50% of the width of the screen, and stretch image with column. Everything works as shown in the picture, until I insert it into SingleChildScrollView. After that, the application crashes until I set the exact height of the image.

enter image description here

Question: how to do this WITHOUT specifying the height of the image? I can't set height anywhere inside Row, because I don't know exact size а the image.


Solution

  • try this:

    SingleChildScrollView(
                  scrollDirection: Axis.vertical,
                  child: Row(
                    children: [
                      Expanded(
                          child: Image.asset(
                        'assets/images/test.jpeg',
                        fit: BoxFit.contain,
                      )),
                      Expanded(
                          child: Image.asset(
                        'assets/images/test.jpeg',
                        fit: BoxFit.contain,
                      ))
                    ],
                  ),
                ),
    

    enter image description here