Merge branch 'lots' of hackku/flutter-app into master
This commit is contained in:
commit
21816ac1d6
@ -1,5 +1,6 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
@ -7,7 +8,8 @@ class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Names',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData.dark(),
|
||||
home: MyHomePage(),
|
||||
);
|
||||
}
|
||||
@ -22,59 +24,156 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final db = Firestore.instance.collection('lots');
|
||||
static int lot = 5;
|
||||
static int col = 4;
|
||||
|
||||
// Future<List<LotRecord>> getLots(Future<>) async{
|
||||
// List<lotRecord> lotList =
|
||||
//
|
||||
// return lotList;
|
||||
//}
|
||||
void getLot(){
|
||||
print("pressed");
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void _swichLayout(){
|
||||
setState(() {
|
||||
if (col == 2){
|
||||
print("col = 2");
|
||||
col=4;
|
||||
}
|
||||
else {
|
||||
print("col =" + col.toString());
|
||||
col =2;
|
||||
}
|
||||
});
|
||||
}
|
||||
void _onItemTapped(int index) {
|
||||
getLot();
|
||||
setState(() {
|
||||
index == 0 ? lot-- : lot++;
|
||||
});
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Lot 1')),
|
||||
body: _buildBody(
|
||||
context, db.document('Test-Lot-46').collection('stalls')),
|
||||
);
|
||||
}
|
||||
|
||||
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) {
|
||||
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: Colors.blue,
|
||||
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text("Stall " + record.stall.toString(),
|
||||
style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
subtitle: Text(record.open.toString()),
|
||||
),
|
||||
],),
|
||||
appBar: AppBar(title: Text("Lot Number: " + lot.toString()), centerTitle: true,),
|
||||
body:
|
||||
// _buildLot(context, db),
|
||||
_buildBody(
|
||||
context, db.document("Lot" + lot.toString()).collection('stalls'), col),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
// type: BottomNavigationBarType.shifting ,
|
||||
items: <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(icon: Icon(Icons.arrow_back, color: Colors.white70), title: Text('Last Lot', style: TextStyle(color: Colors.white))),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.arrow_forward, color: Colors.white70), title: Text('Next Lot', style: TextStyle(color: Colors.white))),
|
||||
],
|
||||
currentIndex: 0,
|
||||
fixedColor: Colors.deepPurple,
|
||||
onTap: _onItemTapped,
|
||||
),
|
||||
|
||||
|
||||
floatingActionButton: FloatingActionButton(onPressed: _swichLayout),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Widget _(BuildContext context, CollectionReference stallDB, int col) {
|
||||
return StreamBuilder<QuerySnapshot>(
|
||||
stream: stallDB.snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return LinearProgressIndicator();
|
||||
|
||||
return _buildList(context, snapshot.data.documents, col);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(BuildContext context, CollectionReference stallDB,int col) {
|
||||
return StreamBuilder<QuerySnapshot>(
|
||||
stream: stallDB.snapshots(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return LinearProgressIndicator();
|
||||
|
||||
return _buildList(context, snapshot.data.documents,col);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot,int col) {
|
||||
return GridView.count(
|
||||
primary: false,
|
||||
padding: EdgeInsets.all(120/col),
|
||||
childAspectRatio: 2/col,
|
||||
crossAxisSpacing: 5.0,
|
||||
crossAxisCount: col,
|
||||
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
|
||||
final record = Record.fromSnapshot(data);
|
||||
return GestureDetector(
|
||||
onTap: (){ _showInfo(record,context);},
|
||||
child: 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)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
//SimpleDialogOption
|
||||
void _showInfo(Record record, context){
|
||||
print("Record # " + record.stall.toString() + " pressed");
|
||||
String message = '';
|
||||
record.handicap ? message =" is designated for handicap" : message=" is not reserved for handicap";
|
||||
AlertDialog alert = new AlertDialog(
|
||||
content: Text(
|
||||
"Stall # " + record.stall.toString() + message
|
||||
),
|
||||
);
|
||||
showDialog(context: context, child: alert);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class LotRecord {
|
||||
final int lot;
|
||||
final int col;
|
||||
final String name;
|
||||
final DocumentReference reference;
|
||||
|
||||
LotRecord.fromMap(Map<String, dynamic> map, {this.reference})
|
||||
: assert(map['lot'] != null),
|
||||
assert(map['col'] != null),
|
||||
assert(map['name'] != null),
|
||||
lot = map['lot'],
|
||||
col = map['col'],
|
||||
name = map['name'];
|
||||
|
||||
|
||||
LotRecord.fromSnapshot(DocumentSnapshot snapshot)
|
||||
: this.fromMap(snapshot.data, reference: snapshot.reference);
|
||||
|
||||
@override
|
||||
String toString() => "Record<$lot>";
|
||||
}
|
||||
|
||||
|
||||
class Record {
|
||||
final int stall;
|
||||
final int passID;
|
||||
@ -92,8 +191,6 @@ class Record {
|
||||
open = map['open'],
|
||||
handicap = map['handicap'];
|
||||
|
||||
|
||||
|
||||
Record.fromSnapshot(DocumentSnapshot snapshot)
|
||||
: this.fromMap(snapshot.data, reference: snapshot.reference);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: flutter_app
|
||||
name: waitNoMore
|
||||
description: A new Flutter application.
|
||||
|
||||
# The following defines the version and build number for your application.
|
||||
|
@ -1,30 +0,0 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility that Flutter provides. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:flutter_app/main.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(MyApp());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user