Home > front end >  how to get snapshot all in an array flutter firebase cloud
how to get snapshot all in an array flutter firebase cloud

Time:09-10

I am trying to get all of the data info. in my firebase cloud firestore but am still struggling with the code:

StreamBuilder<DocumentSnapshot?>(
  stream: FirebaseFirestore.instance
      .collection("groups")
      .doc(groupId)
      .snapshots(),
  builder: (context, snapshot) {
    return GridView.builder(
          gridDelegate:
          const SliverGridDelegateWithFixedCrossAxisCount(
       crossAxisCount: 2,
     ),

          itemBuilder: (context, index) {
            return SizedBox(
              child: snapshot.data!.get('members')[index][0],
              height: 20,
              width: 10,
            );
          });
  }),

enter image description here I want to snapshot all of this and display it in my app

I don’t think I did it right cuz this is the error that I get

ErrorDescription( 'Viewports expand in the scrolling direction to fill their container. ' 'In this case, a vertical viewport was given an unlimited amount of ' 'vertical space in which to expand. This situation typically happens ' 'when a scrollable widget is nested inside another scrollable widget.',

CodePudding user response:

You're adding a [0] that isn't needed.

Change:

snapshot.data!.get('members')[index][0],

To:

snapshot.data!.get('members')[index],

Note that I'm not sure if that'll also fix your layout issue, but is definitely a problem with your code. If you still get the same layout problem after this fix, a search for the error message may provide useful results.

CodePudding user response:

Try changing

snapshot.data!.get('members')[index][0],

to

Text(
  snapshot.data!.get('members')[index],
),
  • Related