skip to Main Content

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),
]
)
)

}
)
]
)
)

3

Answers


  1. Try these two steps:

    1. Wrap the ListView.builder inside an Expanded widget.
    2. Ensure that the height of the Container widget in your code is enough to contain the reviews.name + reviews.reviewBody.
    Login or Signup to reply.
  2. Wrap your ListView inside Expanded

    return Scaffold(
    appBar: HoomeAppBar(context),
    body: Column(
        children: [
             Text('home'),
             Expanded (             <- Add it here   
               ListView.builder(
                ...
             )
         ]
      )
    );
    
    Login or Signup to reply.
  3. return Scaffold(
        appBar: HoomeAppBar(context),
        body: Column(
            children: [
                 Text('home'),
                 Expanded (             //Add this widget
                   ListView.builder(
                    ...
                 )
             ]
          )
        );
    
    1. Wrap the ListView.builder inside an Expanded widget.
    2. Remove container width & height and add column property mainAxisSize: MainAxisSize.min
      so name & reviews text display with dynamic content.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search