This commit is contained in:
NATHANIEL ENDICK
2023-02-26 00:03:59 -05:00
3 changed files with 105 additions and 37 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'meetings.dart'; import 'meetings.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class MainScreen extends StatefulWidget { class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key); const MainScreen({Key? key}) : super(key: key);
@@ -11,6 +13,13 @@ class MainScreen extends StatefulWidget {
class _MainScreenState extends State<MainScreen> { class _MainScreenState extends State<MainScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("OOOGABOOGA");
getSellers(Filter(
["Sbarro"],
PriceRange(8, 10),
TimeRange(Timestamp.fromDate(DateTime(2023, 2, 26, 12, 50)),
Timestamp.fromDate(DateTime(2023, 2, 26, 11, 50)))))
.then((value) => {print(value)});
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Main Beens"), title: const Text("Main Beens"),

View File

@@ -3,45 +3,78 @@ import 'dart:ffi';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
class TimeRange { class TimeRange {
late DateTime startTime; late Timestamp startTime;
late DateTime endTime; late Timestamp endTime;
TimeRange(this.startTime, this.endTime); TimeRange(this.startTime, this.endTime);
} }
class Seller { class PriceRange {
int low = 0;
int high = 0;
PriceRange(this.low, this.high);
}
class Seller implements Comparable<Seller> {
String name = ""; String name = "";
String uid = ""; String uid = "";
String location = ""; List<dynamic> location;
TimeRange availableTime; TimeRange availableTime;
Int64 price; int price;
Seller(this.name, this.uid, this.location, this.availableTime, this.price); Seller(this.name, this.uid, this.location, this.availableTime, this.price);
@override
String toString() {
return "Name: $name, Price: $price";
}
@override
int compareTo(Seller other) {
return this.name.compareTo(other.name);
}
} }
class Filter { class Filter {
String? location; List<String>? locations;
Int64? price; PriceRange? price;
TimeRange? meetingTime; TimeRange? meetingTime;
Filter(this.location, this.price, this.meetingTime); Filter(this.locations, this.price, this.meetingTime);
} }
Future<List<Seller>> getSellers(Filter filter) async { Future<List<Seller>> getSellers(Filter filter) async {
CollectionReference users = FirebaseFirestore.instance.collection('sellers'); CollectionReference users = FirebaseFirestore.instance.collection('sellers');
List<Seller> sellers = List.empty(); List<Seller> sellers = List.empty(growable: true);
final Query query = users final Query query = users
.where('location', isEqualTo: filter.location) .where('location', arrayContainsAny: filter.locations)
.where('price', isEqualTo: filter.price) .where('price',
.where('start-time', isGreaterThanOrEqualTo: filter.price?.low,
isGreaterThanOrEqualTo: filter.meetingTime?.startTime) isLessThanOrEqualTo: filter.price?.high);
.where('end-time', isLessThanOrEqualTo: filter.meetingTime?.endTime);
final QuerySnapshot snapshot = await query.get(); final QuerySnapshot snapshot = await query.get();
for (var doc in snapshot.docs) { final startTime = filter.meetingTime?.endTime;
sellers.add(Seller(doc["name"], doc["uid"], doc["location"], final endTime = filter.meetingTime?.startTime;
TimeRange(doc["start-time"], doc["end-time"]), doc["price"]));
if (startTime != null && endTime != null) {
var docs = snapshot.docs
.where((element) =>
startTime.compareTo(element["start-time"]) > 0 ||
element["start-time"] == (startTime))
.where((element) =>
endTime.compareTo(element["end-time"]) < 0 ||
element["end-time"] == (endTime));
for (var doc in docs) {
sellers.add(Seller(doc["name"], doc["uid"], doc["location"],
TimeRange(doc["start-time"], doc["end-time"]), doc["price"]));
}
} else {
for (var doc in snapshot.docs) {
sellers.add(Seller(doc["name"], doc["uid"], doc["location"],
TimeRange(doc["start-time"], doc["end-time"]), doc["price"]));
}
} }
return sellers; return sellers;
} }

View File

@@ -8,33 +8,65 @@ class SellScreen extends StatefulWidget {
} }
class _SellScreenState extends State<SellScreen> { class _SellScreenState extends State<SellScreen> {
Map<String, bool> values = {
'Busch Dining Hall': false,
'Livingston Dining Hall': false,
'Brower Dining Hall': false,
'Neilson Dining Hall': false,
'Cafe West': false,
'Cook Cafe': false,
'Douglass Cafe': false,
'Harvest INFH': false,
'Kilmer\'s Market': false,
'College Ave Dining Hall': false,
'Red Pine Pizza': false,
'Rock Cafe': false,
'Sbarro': false,
'Woody\'s Cafe': false,
};
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TimeOfDay _time = TimeOfDay.now(); TimeOfDay time = TimeOfDay.now();
return Scaffold( return Scaffold(
body: Column( body: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.store_mall_directory, color: Colors.red), Icon(Icons.store_mall_directory, color: Colors.red),
const Text('Place'), const Text('Place'),
ListTile( ConstrainedBox(
title: Text(_time.format(context)), constraints: BoxConstraints.expand(height: 100),
onTap: () { child: ListView(
Future<TimeOfDay?> selectedTime = showTimePicker( children: values.keys.map((String key) {
context: context, return CheckboxListTile(
initialTime: _time, title: Text(key),
); value: values[key],
setState(() { onChanged: (bool? value) {
selectedTime.then((value) => _time = value!); setState(() {
_time = TimeOfDay(hour: 10, minute: 00); values[key] = value!;
}); });
}, },
);
}).toList(),
),
), ),
LocationDropdown(), LocationDropdown(),
Icon(Icons.access_time, color: Colors.red), Icon(Icons.access_time, color: Colors.red),
Expanded( Expanded(
child: const Text('Time'), child: const Text('Time'),
), ),
ListTile(
title: Text(time.format(context)),
onTap: () {
Future<TimeOfDay?> selectedTime = showTimePicker(
context: context,
initialTime: time,
);
setState(() {
selectedTime.then((value) => time = value!);
time = TimeOfDay(hour: 10, minute: 00);
});
},
),
Icon(Icons.attach_money, color: Colors.red), Icon(Icons.attach_money, color: Colors.red),
Expanded( Expanded(
child: const Text('Cost'), child: const Text('Cost'),
@@ -45,13 +77,7 @@ class _SellScreenState extends State<SellScreen> {
} }
} }
const List<String> list = <String>[ const List<String> list = <String>['Brower', 'BDH', 'LDH', 'Neilson', 'Woody\'s'];
'Brower',
'BDH',
'LDH',
'Neilson',
'Woody\'s'
];
class LocationDropdown extends StatefulWidget { class LocationDropdown extends StatefulWidget {
const LocationDropdown({super.key}); const LocationDropdown({super.key});