Home > Enterprise >  Why does my flutter ListView.Builder gives renderflex overflowed error?
Why does my flutter ListView.Builder gives renderflex overflowed error?

Time:01-06

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:

  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.

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(
                ...
             )
         ]
      )
    );
  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.
  • Related