TarushiAg
TarushiAg

Reputation: 234

Expanded Widget occupies the whole screen

When I use the Expanded widget with my ListView in a Column or a Row, it occupies the entire screen and doesn't fit to the size of the list. Is there any way to fit my Column or Row to the exact size of my list returned with the ListView? I don't want it to occupy the entire screen as I have two buttons which get pushed to the end of the screen because of the unnecessary space the Expanded widget takes. And the Listview doesn't seem to work without Expanded widget.

Upvotes: 0

Views: 2094

Answers (1)

Mohanned Kashpour
Mohanned Kashpour

Reputation: 21

You have 3 options to solve this issue:

First way: remove Expanded and use the property shrinkWrap in the ListView and set it to true, this is the easiest way but this has some drawbacks, please check out Flutter official docs for more details.

Second way: remove Expanded and replace it with SizedBox or Container and set an explicit height like 300.

Third way: use CustomScrollView as your body and use SliverListView instead of ListView and use SliverToBoxAdapter with Row as a child, please read the Flutter official docs for more detail about using Slivers

Upvotes: 2

Related Questions