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

thomas-mark2
Thomas Atkins 5 years ago
parent f5ded6fa18
commit 27e656c93b

@ -22,7 +22,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
final db = Firestore.instance.collection('lots'); final db = Firestore.instance.collection('lots');
static int lot = 26; static int lot = 25;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -31,11 +31,14 @@ class _MyHomePageState extends State<MyHomePage> {
body: body:
// _buildLot(context, db), // _buildLot(context, db),
_buildBody( _buildBody(
context, db.document("Lot" + lot.toString()).collection('stalls')), context, db.document("Lot" + lot.toString()).collection('stalls'), 4),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
child: Text("Next Lot"), child: Text("Next Lot"),
onPressed: () {
setState(() {
lot++;
});
},
), ),
); );
@ -64,41 +67,43 @@ Widget _buildListLotItem(BuildContext context, DocumentSnapshot data) {
return Text(record.stall.toString()); return Text(record.stall.toString());
} }
Widget _(BuildContext context, CollectionReference stallDB) { Widget _(BuildContext context, CollectionReference stallDB, int col) {
return StreamBuilder<QuerySnapshot>( return StreamBuilder<QuerySnapshot>(
stream: stallDB.snapshots(), stream: stallDB.snapshots(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator(); 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<QuerySnapshot>( return StreamBuilder<QuerySnapshot>(
stream: stallDB.snapshots(), stream: stallDB.snapshots(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator(); if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents); return _buildList(context, snapshot.data.documents, col);
}, },
); );
} }
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) { Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot,
int col) {
return GridView.count( return GridView.count(
primary: false, primary: false,
padding: const EdgeInsets.all(60), padding: const EdgeInsets.all(60),
crossAxisSpacing: 1.0, crossAxisSpacing: 5.0,
crossAxisCount: 2, crossAxisCount: col,
children: snapshot.map((data) => _buildListItem(context, data)).toList(), children: snapshot.map((data) => _buildListItem(context, data)).toList(),
); );
} }
Widget _buildListItem(BuildContext context, DocumentSnapshot data) { Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final record = Record.fromSnapshot(data); final record = Record.fromSnapshot(data);
return Card( return
Card(
key: ValueKey(record.stall), key: ValueKey(record.stall),
color: (record.open ? Colors.green[200] : Colors.red[100]), color: (record.open ? Colors.green[200] : Colors.red[100]),
child: Center( child: Center(

Loading…
Cancel
Save