Dmitry Z
Dmitry Z

Reputation: 39

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.

Upvotes: 1

Views: 706

Answers (2)

Darshan Sheta
Darshan Sheta

Reputation: 59

Try flexible instead of expanded

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

Upvotes: 0

eamirho3ein
eamirho3ein

Reputation: 17940

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

Upvotes: 2

Related Questions