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 e08e43625e
commit f5ded6fa18

@ -22,16 +22,49 @@ 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;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: Text('Lot 1')), appBar: AppBar(title: Text(lot.toString())),
body: _buildBody( body:
context, db.document('Lot1').collection('stalls')), // _buildLot(context, db),
_buildBody(
context, db.document("Lot" + lot.toString()).collection('stalls')),
floatingActionButton: FloatingActionButton(
child: Text("Next Lot"),
),
); );
} }
}
Widget _buildBody(BuildContext context, CollectionReference stallDB) { Widget _buildLot(BuildContext context, CollectionReference lotDB) {
return StreamBuilder<QuerySnapshot>(
stream: lotDB.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildLotList(context, snapshot.data.documents);
},
);
}
Widget _buildLotList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
children:
snapshot.map((data) => _buildListLotItem(context, data)).toList(),
);
}
Widget _buildListLotItem(BuildContext context, DocumentSnapshot data) {
final record = LotRecord.fromSnapshot(data);
return Text(record.stall.toString());
}
Widget _(BuildContext context, CollectionReference stallDB) {
return StreamBuilder<QuerySnapshot>( return StreamBuilder<QuerySnapshot>(
stream: stallDB.snapshots(), stream: stallDB.snapshots(),
builder: (context, snapshot) { builder: (context, snapshot) {
@ -40,9 +73,20 @@ class _MyHomePageState extends State<MyHomePage> {
return _buildList(context, snapshot.data.documents); return _buildList(context, snapshot.data.documents);
}, },
); );
} }
Widget _buildBody(BuildContext context, CollectionReference stallDB) {
return StreamBuilder<QuerySnapshot>(
stream: stallDB.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
return _buildList(context, snapshot.data.documents);
},
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) { Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return GridView.count( return GridView.count(
primary: false, primary: false,
padding: const EdgeInsets.all(60), padding: const EdgeInsets.all(60),
@ -50,14 +94,13 @@ class _MyHomePageState extends State<MyHomePage> {
crossAxisCount: 2, crossAxisCount: 2,
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);
if (record.open) {
return Card( return Card(
key: ValueKey(record.stall), key: ValueKey(record.stall),
color: Colors.green[300], color: (record.open ? Colors.green[200] : Colors.red[100]),
child: Center( child: Center(
child: Column( child: Column(
children: [ children: [
@ -66,40 +109,46 @@ class _MyHomePageState extends State<MyHomePage> {
style: TextStyle(fontWeight: FontWeight.w500)), style: TextStyle(fontWeight: FontWeight.w500)),
subtitle: Text(record.open.toString()), 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()),
),
],),
), ),
);
}
); class LotRecord {
} final int stall;
final int passID;
final bool open;
final bool handicap;
final DocumentReference reference;
} LotRecord.fromMap(Map<String, dynamic> 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 Record {
class lotRecord {
final int stall; final int stall;
final int passID; final int passID;
final bool open; final bool open;
final bool handicap; final bool handicap;
final DocumentReference reference; final DocumentReference reference;
Record.fromMap(Map<String, dynamic> map, {this.reference}) lotRecord.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['handicap'] != null), : assert(map['handicap'] != null),
assert(map['stall'] != null), assert(map['stall'] != null),
assert(map['passID'] != null), assert(map['passID'] != null),
@ -109,7 +158,30 @@ class Record {
open = map['open'], open = map['open'],
handicap = map['handicap']; 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<String, dynamic> 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) Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference); : this.fromMap(snapshot.data, reference: snapshot.reference);

Loading…
Cancel
Save