Compare commits
No commits in common. "master" and "thomas-mark2" have entirely different histories.
master
...
thomas-mar
@ -1,6 +1,5 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
@ -8,8 +7,7 @@ class MyApp extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
title: 'Names',
|
||||||
theme: ThemeData.dark(),
|
|
||||||
home: MyHomePage(),
|
home: MyHomePage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -24,64 +22,50 @@ 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 = 5;
|
static int lot = 25;
|
||||||
static int col = 4;
|
|
||||||
|
|
||||||
// Future<List<LotRecord>> getLots(Future<>) async{
|
|
||||||
// List<lotRecord> lotList =
|
|
||||||
//
|
|
||||||
// return lotList;
|
|
||||||
//}
|
|
||||||
void getLot(){
|
|
||||||
print("pressed");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text("Lot Number: " + lot.toString()), centerTitle: true,),
|
appBar: AppBar(title: Text(lot.toString())),
|
||||||
body:
|
body:
|
||||||
// _buildLot(context, db),
|
// _buildLot(context, db),
|
||||||
_buildBody(
|
_buildBody(
|
||||||
context, db.document("Lot" + lot.toString()).collection('stalls'), col),
|
context, db.document("Lot" + lot.toString()).collection('stalls'), 4),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
floatingActionButton: FloatingActionButton(
|
||||||
// type: BottomNavigationBarType.shifting ,
|
child: Text("Next Lot"),
|
||||||
items: <BottomNavigationBarItem>[
|
onPressed: () {
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.arrow_back, color: Colors.white70), title: Text('Last Lot', style: TextStyle(color: Colors.white))),
|
setState(() {
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.arrow_forward, color: Colors.white70), title: Text('Next Lot', style: TextStyle(color: Colors.white))),
|
lot++;
|
||||||
],
|
});
|
||||||
currentIndex: 0,
|
},
|
||||||
fixedColor: Colors.deepPurple,
|
|
||||||
onTap: _onItemTapped,
|
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(onPressed: _swichLayout),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, int col) {
|
Widget _(BuildContext context, CollectionReference stallDB, int col) {
|
||||||
return StreamBuilder<QuerySnapshot>(
|
return StreamBuilder<QuerySnapshot>(
|
||||||
@ -94,22 +78,22 @@ Widget _(BuildContext context, CollectionReference stallDB, int col) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBody(BuildContext context, CollectionReference stallDB,int col) {
|
Widget _buildBody(BuildContext context, CollectionReference stallDB, int col) {
|
||||||
return StreamBuilder<QuerySnapshot>(
|
return StreamBuilder<QuerySnapshot>(
|
||||||
stream: stallDB.snapshots(),
|
stream: stallDB.snapshots(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (!snapshot.hasData) return LinearProgressIndicator();
|
if (!snapshot.hasData) return LinearProgressIndicator();
|
||||||
|
|
||||||
return _buildList(context, snapshot.data.documents,col);
|
return _buildList(context, snapshot.data.documents, col);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot,int col) {
|
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot,
|
||||||
|
int col) {
|
||||||
return GridView.count(
|
return GridView.count(
|
||||||
primary: false,
|
primary: false,
|
||||||
padding: EdgeInsets.all(120/col),
|
padding: const EdgeInsets.all(60),
|
||||||
childAspectRatio: 2/col,
|
|
||||||
crossAxisSpacing: 5.0,
|
crossAxisSpacing: 5.0,
|
||||||
crossAxisCount: col,
|
crossAxisCount: col,
|
||||||
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
|
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
|
||||||
@ -118,9 +102,8 @@ Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot,int col)
|
|||||||
|
|
||||||
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
|
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
|
||||||
final record = Record.fromSnapshot(data);
|
final record = Record.fromSnapshot(data);
|
||||||
return GestureDetector(
|
return
|
||||||
onTap: (){ _showInfo(record,context);},
|
Card(
|
||||||
child: Card(
|
|
||||||
key: ValueKey(record.stall),
|
key: ValueKey(record.stall),
|
||||||
color: (record.open ? Colors.green[200] : Colors.red[100]),
|
color: (record.open ? Colors.green[200] : Colors.red[100]),
|
||||||
child: Center(
|
child: Center(
|
||||||
@ -129,48 +112,62 @@ Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text("Stall " + record.stall.toString(),
|
title: Text("Stall " + record.stall.toString(),
|
||||||
style: TextStyle(fontWeight: FontWeight.w500)),
|
style: TextStyle(fontWeight: FontWeight.w500)),
|
||||||
|
subtitle: Text(record.open.toString()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//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 {
|
class LotRecord {
|
||||||
final int lot;
|
final int stall;
|
||||||
final int col;
|
final int passID;
|
||||||
final String name;
|
final bool open;
|
||||||
|
final bool handicap;
|
||||||
final DocumentReference reference;
|
final DocumentReference reference;
|
||||||
|
|
||||||
LotRecord.fromMap(Map<String, dynamic> map, {this.reference})
|
LotRecord.fromMap(Map<String, dynamic> map, {this.reference})
|
||||||
: assert(map['lot'] != null),
|
: assert(map['handicap'] != null),
|
||||||
assert(map['col'] != null),
|
assert(map['stall'] != null),
|
||||||
assert(map['name'] != null),
|
assert(map['passID'] != null),
|
||||||
lot = map['lot'],
|
assert(map['open'] != null),
|
||||||
col = map['col'],
|
stall = map['stall'],
|
||||||
name = map['name'];
|
passID = map['passID'],
|
||||||
|
open = map['open'],
|
||||||
|
handicap = map['handicap'];
|
||||||
|
|
||||||
LotRecord.fromSnapshot(DocumentSnapshot snapshot)
|
LotRecord.fromSnapshot(DocumentSnapshot snapshot)
|
||||||
: this.fromMap(snapshot.data, reference: snapshot.reference);
|
: this.fromMap(snapshot.data, reference: snapshot.reference);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => "Record<$lot>";
|
String toString() => "Record<$stall>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: waitNoMore
|
name: flutter_app
|
||||||
description: A new Flutter application.
|
description: A new Flutter application.
|
||||||
|
|
||||||
# The following defines the version and build number for your application.
|
# The following defines the version and build number for your application.
|
||||||
|
30
flutter_app/test/widget_test.dart
Normal file
30
flutter_app/test/widget_test.dart
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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