mardi 30 juin 2020

Random/shuffle data using streambuilder? flutter

is there a way to randomise data coming from firestore? i am using a streambuilder and a staggeredview.countbuilder . i could not find any docs about it! right now the data comes in the last signup order into the stream. can someone help? best regards everybody

this is my code

StreamBuilder(
  stream: Firestore.instance.collection('users').where('myCity', isEqualTo: city).snapshots(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) return Text('Loading');
    return  Container(
      child: StaggeredGridView.countBuilder(
        crossAxisCount: 2,
          crossAxisSpacing: 12,
          mainAxisSpacing: 12,
          itemCount: snapshot.data.documents.length,
          itemBuilder: (BuildContext context, int index) {
            User user = User.fromDoc(snapshot.data
                .documents[index]);
            return GestureDetector(
              child: Container(
                decoration: BoxDecoration(
                    color: Colors.transparent,
                borderRadius: BorderRadius.all(Radius.circular(12))

              ),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(21),
                  child: Image.network(user.profileImageUrl,fit: BoxFit.cover,)
                ),
            )
            );
            },
        staggeredTileBuilder: (index){
          return StaggeredTile.count(0, index.isEven? 1.2 :1.4);
      },
          ),
    );
  },
);



Aucun commentaire:

Enregistrer un commentaire