I am trying to implement a listview builder in my flutter app to generate a scrollable list of reviews, but for some reason its giving me a renderflex overflow error. This doesn't make any sense because a list view is designed to overflow the screen thats what the whole point of it is.
this is the gist of the code I currently have thats giving me the error.
return Scaffold(
appBar: HoomeAppBar(context),
body: Column(
children: [
Text('home'),
ListView.builder(
itemCount: 2,
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
width: 200,
height: 300,
child: Column(
children: [
Text(reviews[index].name),
Text(reviews[index].reviewBody),
]
)
)
}
)
]
)
)
CodePudding user response:
Try these two steps:
- Wrap the ListView.builder inside an Expanded widget.
- Ensure that the height of the Container widget in your code is enough to contain the reviews.name reviews.reviewBody.
CodePudding user response:
Wrap your ListView
inside Expanded
return Scaffold(
appBar: HoomeAppBar(context),
body: Column(
children: [
Text('home'),
Expanded ( <- Add it here
ListView.builder(
...
)
]
)
);
CodePudding user response:
return Scaffold(
appBar: HoomeAppBar(context),
body: Column(
children: [
Text('home'),
Expanded ( //Add this widget
ListView.builder(
...
)
]
)
);
- Wrap the
ListView.builder
inside anExpanded
widget. - Remove container
width
&height
and add column propertymainAxisSize: MainAxisSize.min
so name & reviews text display with dynamic content.