2019-02-09 05:41:49 +00:00
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Names',
|
|
|
|
home: MyHomePage(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_MyHomePageState createState() {
|
|
|
|
return _MyHomePageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2019-02-09 17:59:31 +00:00
|
|
|
final db = Firestore.instance.collection('lots');
|
|
|
|
|
2019-02-09 05:41:49 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2019-02-09 09:08:01 +00:00
|
|
|
appBar: AppBar(title: Text('Lot 1')),
|
2019-02-09 17:59:31 +00:00
|
|
|
body: _buildBody(context, db),
|
2019-02-09 05:41:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-09 17:59:31 +00:00
|
|
|
Widget _buildBody(BuildContext context, CollectionReference stallDB) {
|
2019-02-09 05:41:49 +00:00
|
|
|
return StreamBuilder<QuerySnapshot>(
|
2019-02-09 17:59:31 +00:00
|
|
|
stream: stallDB.snapshots(),
|
2019-02-09 05:41:49 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) return LinearProgressIndicator();
|
|
|
|
|
|
|
|
return _buildList(context, snapshot.data.documents);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
|
UI is better now... still need to make it change colurs like a camilialine though,,,,,,,,,,,,)
2019-02-09 10:06:45 +00:00
|
|
|
return GridView.count(
|
|
|
|
primary: false,
|
|
|
|
padding: const EdgeInsets.all(60),
|
|
|
|
crossAxisSpacing: 1.0,
|
|
|
|
crossAxisCount: 2,
|
2019-02-09 05:41:49 +00:00
|
|
|
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
|
|
|
|
final record = Record.fromSnapshot(data);
|
|
|
|
|
UI is better now... still need to make it change colurs like a camilialine though,,,,,,,,,,,,)
2019-02-09 10:06:45 +00:00
|
|
|
return Card(
|
2019-02-09 06:06:20 +00:00
|
|
|
key: ValueKey(record.stall),
|
UI is better now... still need to make it change colurs like a camilialine though,,,,,,,,,,,,)
2019-02-09 10:06:45 +00:00
|
|
|
color: Colors.blue,
|
|
|
|
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
title: Text("Stall " + record.stall.toString(),
|
|
|
|
style: TextStyle(fontWeight: FontWeight.w500)),
|
|
|
|
subtitle: Text(record.open.toString()),
|
|
|
|
),
|
|
|
|
],),
|
2019-02-09 05:41:49 +00:00
|
|
|
),
|
UI is better now... still need to make it change colurs like a camilialine though,,,,,,,,,,,,)
2019-02-09 10:06:45 +00:00
|
|
|
|
|
|
|
|
2019-02-09 05:41:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Record {
|
2019-02-09 06:06:20 +00:00
|
|
|
final int stall;
|
2019-02-09 09:08:01 +00:00
|
|
|
final int passID;
|
|
|
|
final bool open;
|
2019-02-09 06:06:20 +00:00
|
|
|
final bool handicap;
|
2019-02-09 05:41:49 +00:00
|
|
|
final DocumentReference reference;
|
|
|
|
|
|
|
|
Record.fromMap(Map<String, dynamic> map, {this.reference})
|
2019-02-09 06:06:20 +00:00
|
|
|
: assert(map['handicap'] != null),
|
2019-02-09 09:08:01 +00:00
|
|
|
assert(map['stall'] != null),
|
|
|
|
assert(map['passID'] != null),
|
|
|
|
assert(map['open'] != null),
|
|
|
|
stall = map['stall'],
|
|
|
|
passID = map['passID'],
|
|
|
|
open = map['open'],
|
2019-02-09 06:06:20 +00:00
|
|
|
handicap = map['handicap'];
|
|
|
|
|
|
|
|
|
2019-02-09 05:41:49 +00:00
|
|
|
|
|
|
|
Record.fromSnapshot(DocumentSnapshot snapshot)
|
|
|
|
: this.fromMap(snapshot.data, reference: snapshot.reference);
|
|
|
|
|
|
|
|
@override
|
2019-02-09 06:06:20 +00:00
|
|
|
String toString() => "Record<$stall>";
|
2019-02-09 05:41:49 +00:00
|
|
|
}
|