简体   繁体   中英

StreamBuilder inside the ListviewBuilder not scrolling

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.....');
      }
    },
  ),

add this line in listView.builder

physics: AlwaysScrollableScrollPhysics(),

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.....');
      }
    },
  ),
  • 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM