1

I have my ListView.builder inside Expanded widget which render widgets correctly on the screen but I cannot scroll the widgets rendered by it.

Widget build(BuildContext context) {
    return Container(
      child: FutureBuilder(
        future: getPostsForUid(),
        builder: (_, snap) {
          return Expanded(
            child: ListView.builder(
              physics: AlwaysScrollableScrollPhysics(),
              shrinkWrap: true,
              itemCount: snap.data.length,
              itemBuilder: (_, index) {
                if (snap.data[index]['post_type'] == 'real_estate') {
                  return realEstate(snap, index);
                }
                else if (snap.data[index]['post_type'] == 'video_sharing') {
                  return videoSharing(snap, index);
                }
                else {
                  return Text('');
                }

              },
            ),
          );
        },
      ),
    );
  }

This renders widgets but there is no overflow but its not Scrollable. Using AlwaysScrollableScrollPhysics, NeverScrollableScrollPhysics, ScrollPhysics in physics doesn't work either. Also tring shrinkWrap as false returns no widgets whatsoever. enter image description here

2
  • Why you are using an Expanded widget as child of a container Commented Feb 6, 2021 at 12:40
  • I do not know how Expanded widget will work without a Flex widget. Try restarting your app first. Can you show us your parent widget of of provided snippet. Commented Feb 6, 2021 at 16:10

2 Answers 2

2

The list view thinks it’s bigger, because your container has no fixed height. Try setting the height of the container to MediaQuery.of(context).size.height and the list view will know its bounds.

Sign up to request clarification or add additional context in comments.

Comments

1

it will not scroll while it's shrinkWrap is true.

try this:

ListView.builder(
              physics: AlwaysScrollableScrollPhysics(),
              itemExtent: 'sizeOfeachElement (ex:100)'

and remove Expanded

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.