-1
I have in the Firestore the following given.
user1 = {'horário':'manhã'}
user2 = {'horário':'manhã'}
user3 = {'horário':'tarde'}
user4 = {'horário':'manhã'}
user5 = {'horário':'tarde'}
I create buttons dynamically with the schedule.
bt1 = manhã
bt1 = manhã
bt1 = tarde
bt1 = manhã
bt1 = tarde
I would like to know how to do not catch repeated data getting.
bt1 = manhã
bt1 = tarde
Use the code available in the documentation of Firestore
class BookList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('books').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting: return new Text('Loading...');
default:
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
return RiasedButton(
child: Text('${document[horario]}')),
);
}
},
);
}
}
Dude. I can’t test it now, as soon as I get a warning! I came to think of harvesting everything in a list and using a toSet() and using this new list to create Listview. Think it’s worth it?
– Fernando Foster
It is worth remembering that
document
is aDocumentSnapshot
. To get the string you must access withdocument[horario]
.– Naslausky
@Fernandofoster I didn’t know that
toSet()
, apparently it is simpler to use it yes.– Matheus Ribeiro
@Naslausky I forgot to reference the name of the same object... I will correct
– Matheus Ribeiro
Face if you have a list a = [1,1,1,2,2,2,3,3,3] and print(a.toSet()) it prints [1,2,3].
– Fernando Foster
@Naslausky Dude what kind of Docmentsnapshot? It’s a right map?
– Fernando Foster
@Fernandofoster I modified the answer to use the
toSet()
. Since I never needed it, I had no idea of the hahaha existence– Matheus Ribeiro
That’s exactly what I needed, man!
– Fernando Foster