0

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: NeverScrollableScrollPhysics(),
              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('');
                }
              },
            ),
          );
        },
      ),
    );
  }

3 Answers 3

1

Try using ScrollPhysics() class, physics: ScrollPhysics(), here is the link for reference for the same.

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

Comments

1

You should set your physics to AlwaysScrollableScrollPhysics(). The docs state the following:

Scroll physics that always lets the user scroll. This overrides the default behavior which is to disable scrolling when there is no content to scroll. It does not override the handling of overscrolling. On Android, overscrolls will be clamped by default and result in an overscroll glow. On iOS, overscrolls will load a spring that will return the scroll view to its normal range when released.

Here is an image of "overscroll glow" for you to understand what that means. https://i.sstatic.net/6mMn4.png

Consider using shrinkWrap: false to expand your contents in case they are bounded.

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('No data available.');
                }
              },
            ),
          );
        },
      ),
    );
  }

See the docs:

3 Comments

adding AlwaysScrollableScrollPhysics() and shrinkWrap to false renders no widgets at all
@zrhl Please make sure that is not due to your else case which renders an empty text. I modified the code in my answer to accommodate for that.
@zrhl Did you test if your code produced the else case?
0

Add Physics:AlwaysScrollable() in your Listview.

2 Comments

Added still not scrollable.
@zrhl is your listview height larger than the viewport height? You might want to shrinkWrap: false in case your contents are bounded. api.flutter.dev/flutter/widgets/ScrollView/shrinkWrap.html

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.