joris

StreamBuilder

Apr 9th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.47 KB | None | 0 0
  1. Widget build(BuildContext context) {
  2.     return StreamBuilder(
  3.       stream: Firestore.instance.collection("categories_item").snapshots(),
  4.       builder: (context, snapshot) {
  5.         if (!snapshot.hasData) {
  6.           return Center(
  7.             child: CircularProgressIndicator(
  8.               valueColor: AlwaysStoppedAnimation<Color>(redMaroon),
  9.             ),
  10.           );
  11.         } else {
  12.           return Scaffold(
  13.             backgroundColor: Color(0xFFFCFAF8),
  14.             body: ListView(
  15.               children: <Widget>[
  16.                 Container(
  17.                   padding: EdgeInsets.only(right: 15.0),
  18.                   width: MediaQuery.of(context).size.width - 30.0,
  19.                   height: MediaQuery.of(context).size.height - 50.0,
  20.                   child: GridView.count(
  21.                     crossAxisCount: 2,
  22.                     primary: false,
  23.                     crossAxisSpacing: 10.0,
  24.                     mainAxisSpacing: 15.0,
  25.                     childAspectRatio: 0.8,
  26.                     children: snapshot.data.documents.map<Widget>((document) {
  27.                       return _buildCardItem(
  28.                         context,
  29.                         document,
  30.                         false,
  31.                         'assets/burger.jpg',
  32.                         false,
  33.                       );
  34.                     }).toList(),
  35.                   ),
  36.                 )
  37.               ],
  38.             ),
  39.           );
  40.         }
  41.       },
  42.     );
  43.   }
Add Comment
Please, Sign In to add comment