Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
-Commented functions
-Deleted blocks of commented code
  • Loading branch information
TomCranitch committed May 7, 2018
1 parent dcf91d8 commit 49c27a7
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 176 deletions.
5 changes: 5 additions & 0 deletions lib/pages/add_event_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class AddEventPageState extends State<AddEventPage> {
final TextEditingController _startTimeController = new TextEditingController();
final TextEditingController _endTimeController = new TextEditingController();

///Submits the form
///
/// The form fields are first validated, and then the event is added to the
/// database. The current user is then added to the Administrator collection
/// of the event with all privileges enabled.
void submitForm () async {
final FormState form = _formKey.currentState;

Expand Down
2 changes: 2 additions & 0 deletions lib/pages/event_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class EventPageState extends State<EventPage> with SingleTickerProviderStateMixi
super.dispose();
}

///Queries the Firestore to see if the current user can can tickets.
///Displays the scan ticket button if appropriate
void canScan() async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
Firestore.instance.document("events/" + widget._eventID + "/administrators/" + user.uid).snapshots.listen((DocumentSnapshot administratorsSnapshot) {
Expand Down
21 changes: 4 additions & 17 deletions lib/pages/event_page_tabs/event_guests_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ class EventGuestPage extends StatefulWidget {

final String _eventID;
EventGuestPage(this._eventID);

//final List<User> attendees = [new User("Tom", "Cranitch"), new User("User", "Two")];
}

class EventGuestPageState extends State<EventGuestPage> {

@override
Widget build(BuildContext context) {
return new Padding(
Expand All @@ -23,37 +22,25 @@ class EventGuestPageState extends State<EventGuestPage> {
children: <Widget>[
new Expanded(
child: new StreamBuilder<QuerySnapshot>(

// Gets all attendees in the current event
stream: Firestore.instance
.collection('events').document(widget._eventID)
.getCollection('attendees')
.snapshots,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Text("Loading...");
//return new Text("hello");
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
return new EventGuestListCard(document.documentID, document.data["Going"]);
//new Text(document.documentID);
}).toList(),
);
},
),

/*new ListView.builder(
itemCount: widget.attendees.length,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new ListTile(
leading: const Icon(Icons.check, color: Colors.greenAccent,),
title: new Text(widget.attendees[index].firstName),
subtitle: new Text(widget.attendees[index].lastName),
),
);
},
)*/
)
]
)
);
}

}
11 changes: 11 additions & 0 deletions lib/pages/event_page_tabs/event_main_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class EventMainTabPageState extends State<EventMainTabPage> with SingleTickerPro
getEntryCode();
}


///Queries OpenStreetMap using the latitude and longitude given in the [location].
///The resulting address is then displayed using setState.
void setAddress(GeoPoint location) async {
String query = "https://nominatim.openstreetmap.org/reverse?format=json&lat="+ location.latitude.toString() + "&lon=" + location.longitude.toString();

Expand All @@ -41,13 +44,15 @@ class EventMainTabPageState extends State<EventMainTabPage> with SingleTickerPro
this.setState(() => widget._address = JSON.decode(response.body)["display_name"]);
}

///Gets the document snapshot of the event with [eventID] and updates the address appropriately
void getEventData (String eventID) async {
Firestore.instance.collection("events").document(eventID).snapshots.listen((DocumentSnapshot eventSnapshot) {
this.setState(() => eventDocumentSnapshot = eventSnapshot);
setAddress(eventSnapshot.data["location"]);
});
}

///Gets the unique ticketing entry code of the current user
void getEntryCode () async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
Firestore.instance.document("events/" + widget._eventId + "/attendees/" + user.uid).snapshots.listen((DocumentSnapshot attendeeSnapshot) {
Expand Down Expand Up @@ -76,6 +81,8 @@ class EventMainTabPageState extends State<EventMainTabPage> with SingleTickerPro
child: new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[

//Column with the event title and address
new Expanded(
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand All @@ -87,6 +94,8 @@ class EventMainTabPageState extends State<EventMainTabPage> with SingleTickerPro
],
),
),

//Entry QR Code
fullScreenQR ? new Container() : new InkWell(
onTap: () {
this.setState(() => fullScreenQR = !fullScreenQR);
Expand All @@ -107,6 +116,8 @@ class EventMainTabPageState extends State<EventMainTabPage> with SingleTickerPro
),
],
),

// If set to display a full screen QR Code, the QR code goes full screen
fullScreenQR ? new InkWell(
splashColor: Colors.greenAccent,
onTap: () => this.setState(() => fullScreenQR = !fullScreenQR),
Expand Down
41 changes: 22 additions & 19 deletions lib/pages/event_page_tabs/event_music_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EventMusicSearchPageState extends State<EventMusicSearchPage>{
querySpotify(widget._searchString);
}

///Queries the Firestore for the Spotify Access Tocken
getAccessToken() async {
Firestore.instance.document("events/" + widget._eventID).snapshots.listen((DocumentSnapshot docSnapshot) {
this.setState(() {
Expand All @@ -36,6 +37,7 @@ class EventMusicSearchPageState extends State<EventMusicSearchPage>{
});
}

///Searches Spotify based on the [query]
querySpotify(String query) async {
if(widget._accessToken == "") {
_data = null;
Expand All @@ -54,6 +56,26 @@ class EventMusicSearchPageState extends State<EventMusicSearchPage>{
});
}

///Queries Spotify with the [content] when the search field is submitted
void onSubmit(String content) {
querySpotify(content);
}

///Votes for song when the song at the specified [index] is tapped
void onSongTap (int index) async {
Firestore.instance.collection("events").document(widget._eventID).getCollection("music")
.document(_data[index]["uri"]).setData(<String, dynamic>{
"played": false,
"name": _data[index]["name"],
"artist": _data[index]["artists"][0]["name"],
"cover": _data[index]["album"]["images"][0]["url"],
});

// TODO: add user vote

this.setState(() => _data.removeAt(index));
}

@override
Widget build(BuildContext context) {
return new Material(
Expand Down Expand Up @@ -91,24 +113,5 @@ class EventMusicSearchPageState extends State<EventMusicSearchPage>{
);
}

void onSubmit(String content) {
querySpotify(content);
}

void onSongTap (int index) async {
Firestore.instance.collection("events").document(widget._eventID).getCollection("music")
.document(_data[index]["uri"]).setData(<String, dynamic>{
"played": false,
"name": _data[index]["name"],
"artist": _data[index]["artists"][0]["name"],
"cover": _data[index]["album"]["images"][0]["url"],
});

// TODO: add user vote

this.setState(() => _data.removeAt(index));
}


}

30 changes: 16 additions & 14 deletions lib/pages/event_page_tabs/event_music_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ class EventMusicPage extends StatefulWidget {
class EventMusicPageState extends State<EventMusicPage>{
Color background = Colors.white; // TODO: very, very hacky. only for brief testing

void onSubmit(BuildContext context, String content) {
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new EventMusicSearchPage(content, widget._eventID)));
}

///Adds the song with [musicID] to the playlist when tapped
void onMusicTap(String musicID) {
background = Colors.greenAccent;
Firestore.instance
.collection('events').document(widget._eventID)
.getCollection('music').document(musicID)
.getCollection('votes').document() //User ID
.setData(<String, dynamic> {
//TODO: 'user'
});
}

@override
Widget build(BuildContext context) {
return new Padding(
Expand Down Expand Up @@ -53,19 +69,5 @@ class EventMusicPageState extends State<EventMusicPage>{
);
}

void onSubmit(BuildContext context, String content) {
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context) => new EventMusicSearchPage(content, widget._eventID)));
}

void onMusicTap(String musicID) {
background = Colors.greenAccent;
Firestore.instance
.collection('events').document(widget._eventID)
.getCollection('music').document(musicID)
.getCollection('votes').document() //User ID
.setData(<String, dynamic> {
//TODO: 'user'
});
}
}

3 changes: 3 additions & 0 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HomePage extends StatefulWidget {

class HomePageState extends State<HomePage> with TickerProviderStateMixin{

///Navigates to the Add Event Page
void addEvent() {
Navigator.of(context).push(new MaterialPageRoute(builder: (context) => new AddEventPage()));
}
Expand All @@ -25,6 +26,8 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin{
),
body: new Material(
color: Colors.deepPurpleAccent,

// Get all events ordered by start time
child: new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('events')
Expand Down
10 changes: 8 additions & 2 deletions lib/pages/scan_barcode_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ class ScanBarcodePageState extends State<ScanBarcodePage>{

List<List> scannedTickets = []; //[Name, Status, Pass]

///Validates the ticket with [qrContent] against the database
///
/// The ticket is first checked to verify that it is for the correct event.
/// It is then confirmed that the user can is registered to attend the current event.
/// Finally, the program checks that the entry code is valid and that the
/// guest has not already entered. If not all conditions are satisfied then
/// an appropriate error message is given.
void checkTicket (String qrContent) async {
List<String> qrContentArray = qrContent.split(",");
if(qrContentArray[0] != widget._eventId) {
this.setState(() {
scannedTickets.add(["Ticket Lookup Failed", "This ticket is for a different event", TicketStatus.Unverified]);

});
// ignore: return_without_value
return;
return; // ignore: return_without_value
}
Firestore.instance.document("events/" + qrContentArray[0] + "/attendees/" + qrContentArray[1]).get().then((DocumentSnapshot attendeeSnapshot) {
Firestore.instance.document("users/" + qrContentArray[1]).get().then((DocumentSnapshot userSnapshot) {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/signin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final GoogleSignIn _googleSignIn = new GoogleSignIn();

class SignInPage extends StatelessWidget {

///Logs in the current user and then navigates to the home page when successful
Future<Null> _ensureLoggedInWithGoogle(BuildContext context) async {
GoogleSignInAccount googleUser = _googleSignIn.currentUser;

Expand Down
109 changes: 0 additions & 109 deletions lib/test.dart

This file was deleted.

Loading

0 comments on commit 49c27a7

Please sign in to comment.