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 'meetings.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
@@ -11,6 +13,13 @@ class MainScreen extends StatefulWidget {
class _MainScreenState extends State<MainScreen> {
@override
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(
appBar: AppBar(
title: const Text("Main Beens"),

View File

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

View File

@@ -8,33 +8,65 @@ class SellScreen extends StatefulWidget {
}
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
Widget build(BuildContext context) {
TimeOfDay _time = TimeOfDay.now();
TimeOfDay time = TimeOfDay.now();
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.store_mall_directory, color: Colors.red),
const Text('Place'),
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);
});
},
ConstrainedBox(
constraints: BoxConstraints.expand(height: 100),
child: ListView(
children: values.keys.map((String key) {
return CheckboxListTile(
title: Text(key),
value: values[key],
onChanged: (bool? value) {
setState(() {
values[key] = value!;
});
},
);
}).toList(),
),
),
LocationDropdown(),
Icon(Icons.access_time, color: Colors.red),
Expanded(
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),
Expanded(
child: const Text('Cost'),
@@ -45,13 +77,7 @@ class _SellScreenState extends State<SellScreen> {
}
}
const List<String> list = <String>[
'Brower',
'BDH',
'LDH',
'Neilson',
'Woody\'s'
];
const List<String> list = <String>['Brower', 'BDH', 'LDH', 'Neilson', 'Woody\'s'];
class LocationDropdown extends StatefulWidget {
const LocationDropdown({super.key});