Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the height of the whole list.builder in flutter

I need to get the whole list.builder height including the part that is out of the screen view
The List children vary in height

i used the GlobalKey method but it is giving me only the height of the list shown in the screen

I found this solution and it’s working and give me the full list.builder height after scrolling event
but when adding more children to the list.builder by changing the state
this code doesn’t work anymore

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

scrollController.addListener(() {
double? fullListViewHeight;

  double fullListHeightHelper = listKey.currentContext!.size!.height +
      scrollController.position.extentAfter;
  fullListView ??= fullListHeightHelper;
}

>Solution :

listview.builder only build the item that shown to user, in order to get the height with GlobalKey method, you can use listView which build all item at the same time. If you don’t know how pass your list to listView , see this example:

List yourList = [...];
_buildList(){
  List<Widget> _children =yourList.map((e) => YourListItem()).toList();

  return ListView(
     key:yourKey,
     children: _children,
   );
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading