This is my code
ListView.builder(
itemCount: customerList.length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Expanded(
child: ListTile(
title: Text(customerList[index].customerName),
subtitle: Column(
children: [
Text(customerList[index].customerID),
Text(customerList[index].customerAddress),
],
),
),
),
);
}),
I have Used Shrink Wrap and Scroll direction and I have tried Getting Rid of the expanded widget but i am still getting this error
here is debug console
The following assertion was thrown during performLayout():
Vertical viewport was given unbounded width.
Viewports expand in the cross axis to fill their container and constrain their children to match their extent in the cross axis. In this case, a vertical shrinkwrapping viewport was given an unlimited amount of horizontal space in which to expand.
RenderBox was not laid out: RenderShrinkWrappingViewport#90e43 relayoutBoundary=up23 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1972 pos 12: 'hasSize'
2
Answers
First, Expanded Widget has a wrong parent.
Expanded widget can be a child of only Column, Row or Flex.
Second, You can’t expand within a
ListView
.in simple words:
ListView
offers infinity of space whileExpanded
allocates all of the available space, So they are working in opposite goals.I think your goal is to make sure the
ListTile
fills the entireContainer
, if so.by default it will fill the container, but you need to set intrinsic dimensions at least a height for the
Container
, as you know how the container works.Container
fills the available space also, which must be prevented as long as it exists within aListView
So, to fix your code:
Expanded
Widget.Container
which wraps theListTile
, or remove it.Hope it helps you.
Remove Container and Expanded Widget your code is working well.
Result: