I have a Container inside a list view builder and I want this container to be dynamic in size according to the size of child of container (here textwidget), so I used expanded widget for container but it gave an error:
incorrect use of ParentDataWidget.
List<String> values = [
"short text",
"long textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong textlong text"
];
body: ListView.builder(
shrinkWrap: true,
itemCount: values.length,
itemBuilder: (context, index) {
return Expanded(
child: Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: const [
BoxShadow(
color: Colors.grey,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(2.0, 2.0),
),
],
),
child: Text(values[index])),
);
}),
I want the container to expand according to the size of text in list of strings.
2
Answers
Try this :
just remove Expanded and give some padding to the container. like below