Removed refrences to name and vote from db

This commit is contained in:
2019-02-09 00:06:20 -06:00
parent 9d1967a9f0
commit f50380306b
2 changed files with 61 additions and 17 deletions

View File

@@ -51,7 +51,7 @@ class _MyHomePageState extends State<MyHomePage> {
final record = Record.fromSnapshot(data);
return Padding(
key: ValueKey(record.name),
key: ValueKey(record.stall),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Container(
decoration: BoxDecoration(
@@ -59,15 +59,15 @@ class _MyHomePageState extends State<MyHomePage> {
borderRadius: BorderRadius.circular(5.0),
),
child: ListTile(
title: Text(record.name),
trailing: Text(record.votes.toString()),
onTap: () => Firestore.instance.runTransaction((transaction) async {
final freshSnapshot = await transaction.get(record.reference);
final fresh = Record.fromSnapshot(freshSnapshot);
await transaction
.update(record.reference, {'votes': fresh.votes + 1});
}),
title: Text(record.stall.toString()),
trailing: Text(record.handicap.toString()),
// onTap: () => Firestore.instance.runTransaction((transaction) async {
//// final freshSnapshot = await transaction.get(record.reference);
//// final fresh = Record.fromSnapshot(freshSnapshot);
////
//// await transaction
//// .update(record.reference, {'votes': fresh.votes + 1});
//// }),
),
),
);
@@ -75,19 +75,21 @@ class _MyHomePageState extends State<MyHomePage> {
}
class Record {
final String name;
final int votes;
final int stall;
final bool handicap;
final DocumentReference reference;
Record.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['name'] != null),
assert(map['votes'] != null),
name = map['name'],
votes = map['votes'];
: assert(map['handicap'] != null),
assert(map['Stall'] != null),
stall = map['Stall'],
handicap = map['handicap'];
Record.fromSnapshot(DocumentSnapshot snapshot)
: this.fromMap(snapshot.data, reference: snapshot.reference);
@override
String toString() => "Record<$name:$votes>";
String toString() => "Record<$stall>";
}