From 27e656c93b8cc473bd9e1f69711d4c3aa59dec52 Mon Sep 17 00:00:00 2001 From: Thomas Atkins Date: Sat, 9 Feb 2019 16:27:47 -0600 Subject: [PATCH] DB is looking a lot better now that she has all her data in order... time to try to dynamicly create view for diffrent lots --- flutter_app/lib/main.dart | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/flutter_app/lib/main.dart b/flutter_app/lib/main.dart index d70a5ce..f021bb0 100644 --- a/flutter_app/lib/main.dart +++ b/flutter_app/lib/main.dart @@ -22,7 +22,7 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { final db = Firestore.instance.collection('lots'); - static int lot = 26; + static int lot = 25; @override Widget build(BuildContext context) { @@ -31,11 +31,14 @@ class _MyHomePageState extends State { body: // _buildLot(context, db), _buildBody( - context, db.document("Lot" + lot.toString()).collection('stalls')), + context, db.document("Lot" + lot.toString()).collection('stalls'), 4), floatingActionButton: FloatingActionButton( child: Text("Next Lot"), - - + onPressed: () { + setState(() { + lot++; + }); + }, ), ); @@ -64,41 +67,43 @@ Widget _buildListLotItem(BuildContext context, DocumentSnapshot data) { return Text(record.stall.toString()); } -Widget _(BuildContext context, CollectionReference stallDB) { +Widget _(BuildContext context, CollectionReference stallDB, int col) { return StreamBuilder( stream: stallDB.snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return LinearProgressIndicator(); - return _buildList(context, snapshot.data.documents); + return _buildList(context, snapshot.data.documents, col); }, ); } -Widget _buildBody(BuildContext context, CollectionReference stallDB) { +Widget _buildBody(BuildContext context, CollectionReference stallDB, int col) { return StreamBuilder( stream: stallDB.snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return LinearProgressIndicator(); - return _buildList(context, snapshot.data.documents); + return _buildList(context, snapshot.data.documents, col); }, ); } -Widget _buildList(BuildContext context, List snapshot) { +Widget _buildList(BuildContext context, List snapshot, + int col) { return GridView.count( primary: false, padding: const EdgeInsets.all(60), - crossAxisSpacing: 1.0, - crossAxisCount: 2, + crossAxisSpacing: 5.0, + crossAxisCount: col, children: snapshot.map((data) => _buildListItem(context, data)).toList(), ); } Widget _buildListItem(BuildContext context, DocumentSnapshot data) { final record = Record.fromSnapshot(data); - return Card( + return + Card( key: ValueKey(record.stall), color: (record.open ? Colors.green[200] : Colors.red[100]), child: Center(