I will explain with simple examble,
class Demo1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: [
Flexible(
child: ListView(
shrinkWrap: true,
children: const [
ListTile(
leading: Icon(Icons.image),
title: Text('with shrinkwrap is true'),
trailing: Icon(Icons.delete_forever),
),
])),
Expanded(
child: Container(
color: Colors.green,
)),
],
),
),
);
}
}
Here the green colored container is not filling the remaining space, so how to fill the remaining area?
Thanks in advance
3
Answers
Try below code and just Remove your first
Flexible
WidgetBoth
Flexible
andExpanded
have flex value 1, so they both request 50% of the available space. So theContainer
child ofExpanded
takes fills only half space, while theListView
, a child ofFlexible
, also requests half the space but needs very little space.You can make
Container
fill the available space by removingFlexible
, soExpanded
that wrapsContainer
will get all the available space.You can use
SingleChildScrollView
instead of using ListView withshrinkWrap: true
.You may also like
CustomScrollView
overSingleChildScrollView
andshrinkWrap:true
.