From f5ded6fa18dff8eaadd4545bba3d43a11625e1cd Mon Sep 17 00:00:00 2001 From: Thomas Atkins Date: Sat, 9 Feb 2019 16:04:56 -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 | 194 ++++++++++++++++++++++++++------------ 1 file changed, 133 insertions(+), 61 deletions(-) diff --git a/flutter_app/lib/main.dart b/flutter_app/lib/main.dart index 7be6ec3..d70a5ce 100644 --- a/flutter_app/lib/main.dart +++ b/flutter_app/lib/main.dart @@ -22,84 +22,133 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { final db = Firestore.instance.collection('lots'); + static int lot = 26; + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text('Lot 1')), - body: _buildBody( - context, db.document('Lot1').collection('stalls')), - ); - } + appBar: AppBar(title: Text(lot.toString())), + body: +// _buildLot(context, db), + _buildBody( + context, db.document("Lot" + lot.toString()).collection('stalls')), + floatingActionButton: FloatingActionButton( + child: Text("Next Lot"), - Widget _buildBody(BuildContext context, CollectionReference stallDB) { - return StreamBuilder( - stream: stallDB.snapshots(), - builder: (context, snapshot) { - if (!snapshot.hasData) return LinearProgressIndicator(); - return _buildList(context, snapshot.data.documents); - }, - ); - } + ), - Widget _buildList(BuildContext context, List snapshot) { - return GridView.count( - primary: false, - padding: const EdgeInsets.all(60), - crossAxisSpacing: 1.0, - crossAxisCount: 2, - children: snapshot.map((data) => _buildListItem(context, data)).toList(), ); } +} - Widget _buildListItem(BuildContext context, DocumentSnapshot data) { - final record = Record.fromSnapshot(data); - if (record.open) { - return Card( - key: ValueKey(record.stall), - color: Colors.green[300], - child: Center( - child: Column( - children: [ - ListTile( - title: Text("Stall " + record.stall.toString(), - style: TextStyle(fontWeight: FontWeight.w500)), - subtitle: Text(record.open.toString()), - ), - ],), - ), - ); - } //if - else { - return Card( - key: ValueKey(record.stall), - color: Colors.red[100], - child: Center( - child: Column( - children: [ - ListTile( - title: Text("Stall " + record.stall.toString(), - style: TextStyle(fontWeight: FontWeight.w500)), - subtitle: Text(record.open.toString()), - ), - ],), - ), - - - ); - } +Widget _buildLot(BuildContext context, CollectionReference lotDB) { + return StreamBuilder( + stream: lotDB.snapshots(), + builder: (context, snapshot) { + if (!snapshot.hasData) return LinearProgressIndicator(); + return _buildLotList(context, snapshot.data.documents); + }, + ); +} - } +Widget _buildLotList(BuildContext context, List snapshot) { + return ListView( + children: + snapshot.map((data) => _buildListLotItem(context, data)).toList(), + ); } -class Record { +Widget _buildListLotItem(BuildContext context, DocumentSnapshot data) { + final record = LotRecord.fromSnapshot(data); + return Text(record.stall.toString()); +} + +Widget _(BuildContext context, CollectionReference stallDB) { + return StreamBuilder( + stream: stallDB.snapshots(), + builder: (context, snapshot) { + if (!snapshot.hasData) return LinearProgressIndicator(); + + return _buildList(context, snapshot.data.documents); + }, + ); +} + +Widget _buildBody(BuildContext context, CollectionReference stallDB) { + return StreamBuilder( + stream: stallDB.snapshots(), + builder: (context, snapshot) { + if (!snapshot.hasData) return LinearProgressIndicator(); + + return _buildList(context, snapshot.data.documents); + }, + ); +} + +Widget _buildList(BuildContext context, List snapshot) { + return GridView.count( + primary: false, + padding: const EdgeInsets.all(60), + crossAxisSpacing: 1.0, + crossAxisCount: 2, + children: snapshot.map((data) => _buildListItem(context, data)).toList(), + ); +} + +Widget _buildListItem(BuildContext context, DocumentSnapshot data) { + final record = Record.fromSnapshot(data); + return Card( + key: ValueKey(record.stall), + color: (record.open ? Colors.green[200] : Colors.red[100]), + child: Center( + child: Column( + children: [ + ListTile( + title: Text("Stall " + record.stall.toString(), + style: TextStyle(fontWeight: FontWeight.w500)), + subtitle: Text(record.open.toString()), + ), + ], + ), + ), + ); +} + + +class LotRecord { final int stall; final int passID; final bool open; final bool handicap; final DocumentReference reference; - Record.fromMap(Map map, {this.reference}) + LotRecord.fromMap(Map map, {this.reference}) + : assert(map['handicap'] != null), + assert(map['stall'] != null), + assert(map['passID'] != null), + assert(map['open'] != null), + stall = map['stall'], + passID = map['passID'], + open = map['open'], + handicap = map['handicap']; + + LotRecord.fromSnapshot(DocumentSnapshot snapshot) + : this.fromMap(snapshot.data, reference: snapshot.reference); + + @override + String toString() => "Record<$stall>"; +} + + +class lotRecord { + final int stall; + final int passID; + final bool open; + final bool handicap; + final DocumentReference reference; + + lotRecord.fromMap(Map map, {this.reference}) : assert(map['handicap'] != null), assert(map['stall'] != null), assert(map['passID'] != null), @@ -109,11 +158,34 @@ class Record { open = map['open'], handicap = map['handicap']; + lotRecord.fromSnapshot(DocumentSnapshot snapshot) + : this.fromMap(snapshot.data, reference: snapshot.reference); + + @override + String toString() => "Record<$stall>"; +} + +class Record { + final int stall; + final int passID; + final bool open; + final bool handicap; + final DocumentReference reference; + + Record.fromMap(Map map, {this.reference}) + : assert(map['handicap'] != null), + assert(map['stall'] != null), + assert(map['passID'] != null), + assert(map['open'] != null), + stall = map['stall'], + passID = map['passID'], + open = map['open'], + handicap = map['handicap']; Record.fromSnapshot(DocumentSnapshot snapshot) : this.fromMap(snapshot.data, reference: snapshot.reference); @override String toString() => "Record<$stall>"; -} \ No newline at end of file +}