StreamBuilder inside the ListviewBuilder not scrolling

Viewed 344

Problem: I am beginner for flutter developing. I tried to get data from firestore and display it. But scrolling listview didn't respond to one finger so I had to use more than one. How to solve this problem.

body: StreamBuilder(
    stream: _firebase_auth.collection("ContactData").snapshots(),
    builder: (BuildContext context, snapshot) {
      if (snapshot.hasData) {
        return ListView.builder(
            itemCount: snapshot.data.docs.length,
            itemExtent: 100.0,
            itemBuilder: (context, index) {
              DocumentSnapshot data = snapshot.data.docs[index];
              return Card(
                child: ListView(padding: EdgeInsets.all(8.0), children: [
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                ]),
              );
            });
      } else {
        return Text('Loading Data.....');
      }
    },
  ),
3 Answers

you should wrap streamBuilder with the SingleChild scroll view or use shrinkWrap: true,physics: ScrollPhysics(),

body: StreamBuilder(
    stream: _firebase_auth.collection("ContactData").snapshots(),
    builder: (BuildContext context, snapshot) {
      if (snapshot.hasData) {
        return ListView.builder(
            shrinkWrap: true,
            physics: ScrollPhysics(),
            itemCount: snapshot.data.docs.length,
            itemExtent: 100.0,
            itemBuilder: (context, index) {
              DocumentSnapshot data = snapshot.data.docs[index];
              return Card(
                child: ListView(padding: EdgeInsets.all(8.0), children: [
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                  Text('sds'),
                ]),
              );
            });
      } else {
        return Text('Loading Data.....');
      }
    },
  ),

add this line in listView.builder

physics: AlwaysScrollableScrollPhysics(),
  • Wrap stream builder with SingleChildScrolView.

This will make the screen a scrollable element.

  • Set physics of ListView.builder to NeverScrollablePhysics.

This will prevent the scrolling of the parent ListView.Builder, but it's okay because it's parent, SingleChildScrollView is scrollable.

  • Set physics of ListView to Scrollable

If you want to, not sure if you want to scroll these items or just display.

Related