Guest User

Untitled

a guest
Jan 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. Future getCategories() async {
  2. var firestore = Firestore.instance;
  3. QuerySnapshot qn = await firestore.collection("categories").getDocuments();
  4. return qn.documents;
  5. }
  6.  
  7. @override
  8. Widget build(BuildContext context) {
  9. return Container(
  10. child:FutureBuilder(
  11. future:getCategories(),
  12. builder:(context, snapshot){
  13. if(snapshot.connectionState == ConnectionState.waiting){
  14. return Center(
  15. child:Text("Loading...")
  16. );
  17. }
  18. else
  19. {
  20. return GridView.builder(
  21. itemCount: snapshot.data.length,
  22. gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
  23. crossAxisSpacing: 6.0, mainAxisSpacing: 6.0, crossAxisCount: 2),
  24. itemBuilder: (BuildContext context, int index) {
  25. return SingleCategory(
  26. category_name: snapshot.data[index].data["title"],
  27. category_picture: snapshot.data[index].data["picture"],
  28. );
  29. }
  30. );
  31. }
  32. }
  33. )
  34. );
Add Comment
Please, Sign In to add comment