Advertisement
LiMIllusion

Untitled

May 12th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Widget _buildBody(BuildContext context) {
  2. return StreamBuilder<QuerySnapshot>(
  3. stream: Firestore.instance.collection("prova").snapshots(),
  4. builder: (context, snapshot) {
  5. // if (!snapshot.hasData) return LinearProgressIndicator();
  6. switch (snapshot.connectionState) {
  7. case ConnectionState.waiting:
  8. return new Center(child: new CircularProgressIndicator());
  9. default:
  10. return _buildList(context, snapshot.data.documents);
  11. }
  12. },
  13. );
  14. }
  15.  
  16. Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
  17. return ListView(
  18. padding: const EdgeInsets.only(top: 20.0),
  19. children: snapshot.map((data) => _buildListItem(context, data)).toList(),
  20. );
  21. }
  22.  
  23. Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
  24. final record = Record.fromSnapshot(data);
  25. String name = record.name;
  26. return Padding(
  27. key: ValueKey(record.name),
  28. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  29. child: Container(
  30. decoration: BoxDecoration(
  31. border: Border.all(color: Colors.grey),
  32. borderRadius: BorderRadius.circular(7.0),
  33. ),
  34. child: ListTile(
  35. title: Text(titolo),
  36. onTap: (){
  37. Firestore.instance.collection("prova").document(data.documentID.toString()).delete().catchError((e){
  38. print(e);
  39. }
  40. );
  41. },
  42. ),
  43. ),
  44. );
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement