diff --git a/lib/buy.dart b/lib/buy.dart index 2f3f054..6c7a367 100644 --- a/lib/buy.dart +++ b/lib/buy.dart @@ -24,6 +24,42 @@ final List entries = [ 'Pearl Morse', 'Jana Munguia' ]; +final List prices = [ + 1.00, + 2.00, + 3.00, + 4.00, + 5.00, + 6.00, + 7.00, + 8.00, + 9.00, + 10.00, +]; +final List startTime = [ + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), +]; +final List endTime = [ + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), + DateTime.now(), +]; final Map nameToAsset = { 'Brower Dining Hall': 'brower.jpg', 'Cafe West': 'cafe_west.jpg', @@ -38,6 +74,20 @@ final Map nameToAsset = { 'Harvest INFH': 'harvest.jpg', 'Red Pine Pizza': 'red_pine.jpg' }; + +Future numberOfSellersAtDiningLocation(String diningLocation) async { + var sellers = await getSellers(Filter([diningLocation], null, null)); + return sellers.length; +} + +Future> numberOfSellersAtEachDiningLocation() async { + List numSellers = []; + for (var diningLocation in entries) { + numSellers.add(await numberOfSellersAtDiningLocation(diningLocation)); + } + return numSellers; +} + final List> eatingLocations = [ ['Brower Dining Hall', 'Cafe West'], ['Busch Dining Hall', 'Woody\'s Cafe'], @@ -46,20 +96,10 @@ final List> eatingLocations = [ 'Kilmer\'s Market', 'Sbarro\'s', ], - [ - 'Neilson Dining Hall', - 'Cook Cafe', - 'Douglass Cafe', - 'Harvest INFH', - 'Red Pine Pizza' - ] + ['Neilson Dining Hall', 'Cook Cafe', 'Douglass Cafe', 'Harvest INFH', 'Red Pine Pizza'] ]; final List colorCodes = [600, 500, 100]; -final List timeBgAssets = [ - 'assets/daytime_swipe.jpg', - 'assets/afternoon_swipe.jpg', - 'assets/nighttime_swipe.jpg' -]; +final List timeBgAssets = ['assets/daytime_swipe.jpg', 'assets/afternoon_swipe.jpg', 'assets/nighttime_swipe.jpg']; class BuyScreen extends StatefulWidget { const BuyScreen({Key? key}) : super(key: key); @@ -69,6 +109,8 @@ class BuyScreen extends StatefulWidget { } class _BuyScreenState extends State { + DateFormat dateFormat = DateFormat("HH:mm aa"); + CampusState _currentState = CampusState.campuses; List _diningOptions = List.empty(); List _sellersAtDiningHall = []; @@ -83,7 +125,7 @@ class _BuyScreenState extends State { children: [ Row(children: [ Container( - padding: EdgeInsets.only(left: 10, top: 20), + padding: EdgeInsets.only(left: 10, top: 35), child: Text( "Campuses", style: TextStyle( @@ -111,8 +153,7 @@ class _BuyScreenState extends State { }); }, child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(25)), + borderRadius: const BorderRadius.all(Radius.circular(25)), child: Column( children: [ Expanded( @@ -142,8 +183,7 @@ class _BuyScreenState extends State { }); }, child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(25)), + borderRadius: const BorderRadius.all(Radius.circular(25)), child: Column( children: [ Expanded( @@ -173,8 +213,7 @@ class _BuyScreenState extends State { }); }, child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(25)), + borderRadius: const BorderRadius.all(Radius.circular(25)), child: Column( children: [ Expanded( @@ -204,8 +243,7 @@ class _BuyScreenState extends State { }); }, child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(25)), + borderRadius: const BorderRadius.all(Radius.circular(25)), child: Column( children: [ Expanded( @@ -237,7 +275,7 @@ class _BuyScreenState extends State { return Scaffold( body: Column(children: [ Container( - padding: EdgeInsets.fromLTRB(0, 30, 0, 0), + padding: EdgeInsets.fromLTRB(0, 35, 0, 0), width: double.infinity, child: ElevatedButton( onPressed: () { @@ -266,12 +304,7 @@ class _BuyScreenState extends State { itemBuilder: (BuildContext context, int index) { return Container( margin: const EdgeInsets.fromLTRB(4, 4, 4, 8), - decoration: BoxDecoration( - border: Border.all( - color: CustomMaterialColor(240, 240, 240).mdColor, - width: 2), - borderRadius: - const BorderRadius.all(Radius.circular(10))), + decoration: BoxDecoration(border: Border.all(color: CustomMaterialColor(240, 240, 240).mdColor, width: 2), borderRadius: const BorderRadius.all(Radius.circular(10))), child: InkWell( onTap: () { setState(() { @@ -280,24 +313,20 @@ class _BuyScreenState extends State { }); }, child: ClipRRect( - borderRadius: - const BorderRadius.all(Radius.circular(10)), + borderRadius: const BorderRadius.all(Radius.circular(10)), child: Container( height: 120, decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.cover, - image: AssetImage("assets/" + - nameToAsset[ - _diningOptions.elementAt(index)]!), + image: AssetImage("assets/" + nameToAsset[_diningOptions.elementAt(index)]!), )), child: BackdropFilter( filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3), child: Container( padding: const EdgeInsets.only(right: 40), alignment: Alignment.bottomRight, - margin: const EdgeInsets.only( - top: 4, left: 20, bottom: 4), + margin: const EdgeInsets.only(top: 4, left: 20, bottom: 4), child: Text( _diningOptions[index], overflow: TextOverflow.ellipsis, @@ -318,179 +347,196 @@ class _BuyScreenState extends State { body: Column( children: [ Padding( - padding: EdgeInsets.fromLTRB(0, 30, 0, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Flexible( - flex: 8, - fit: FlexFit.tight, - child: ElevatedButton( - onPressed: () { - setState(() { - _currentState = CampusState.campuses; - }); - }, - child: const Text("Choose A Different Location")), - ), - Flexible( - flex: 2, - child: ElevatedButton( - onPressed: () {}, - child: const Icon(Icons.filter_list))) - ]), + padding: EdgeInsets.fromLTRB(0, 35, 0, 0), + child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Flexible( + flex: 8, + fit: FlexFit.tight, + child: ElevatedButton( + onPressed: () { + setState(() { + _currentState = CampusState.campuses; + }); + }, + child: const Text("Choose A Different Location")), + ), + Flexible(flex: 2, child: ElevatedButton(onPressed: () {}, child: const Icon(Icons.filter_list))) + ]), ), - Row(children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ Container( padding: EdgeInsets.only(left: 10, bottom: 10), child: Text( - "Available Swipes", + _selectedLocation, style: TextStyle( fontSize: 30, ), ), + ), + Container( + padding: EdgeInsets.only(left: 10, bottom: 10), + child: Text( + "Time: "+dateFormat.format(DateTime.now()), + style: TextStyle( + fontSize: 20, + ), + ), ) + ]), Expanded( child: ListView.builder( physics: const BouncingScrollPhysics(), - itemCount: 30, - padding: EdgeInsets.fromLTRB(10, 0, 10, 0), + padding: const EdgeInsets.fromLTRB(10, 0, 10, 0), itemBuilder: (BuildContext context, int index) { - List sellers = []; - var loc = _diningOptions[index % _diningOptions.length]; - + var loc = _diningOptions[index]; return FutureBuilder>( future: getSellers(Filter([loc], null, null)), - builder: (BuildContext context, - AsyncSnapshot> snapshot) { + builder: (BuildContext context, AsyncSnapshot> snapshot) { if (snapshot.hasData) { final data = snapshot.data ?? []; - String startTimeFmt = DateFormat("h:mm a").format( - data[index % data.length] - .availableTime - .startTime - .toDate()); + String startTimeFmt = DateFormat("h:mm a").format(data[index].availableTime.startTime.toDate()); - String endTimeFmt = DateFormat("h:mm a").format( - data[index % data.length] - .availableTime - .endTime - .toDate()); + String? sellerName = data[index].name; - final price = data[index % data.length].price; + String endTimeFmt = DateFormat("h:mm a").format(data[index].availableTime.endTime.toDate()); + + final price = data[index].price; return InkWell( onTap: () { - showSheet(context, index); + showSheet(context, index, sellerName, price, data[index].availableTime.startTime.toDate(), data[index % data.length].availableTime.endTime.toDate(), + _selectedLocation); + // showDialog( + // context: context, + // builder: (BuildContext context) => Dialog( + // backgroundColor: Theme.of(context).scaffoldBackgroundColor, + // shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))), + // child: Padding( + // padding: const EdgeInsets.all(8.0), + // child: Column( + // mainAxisSize: MainAxisSize.min, + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // const Text('Transaction Details'), + // const SizedBox(height: 15), + // TextButton( + // onPreslectedd: () { + // Navigator.pop(context); + // }, + // child: const Text('Close'), + // ), + // ], + // ), + // ))); + // // Dialogs.materialDialog( + // // color: Theme.of(context).scaffoldBackgroundColor, + // // customView: const TransactionDetails(), + // // customViewPosition: + // // CustomViewPosition.BEFORE_ACTION, + // // msgAlign: TextAlign.center, + // // msg: + // // 'Please read all the information below before purchasing.\n', + // // title: 'Transaction Details', + // // context: context, + // // actions: [ + // // IconsOutlineButton( + // // onPressed: () {}, + // // text: 'Cancel', + // // iconData: Icons.cancel_outlined, + // // color: Theme.of(context).primaryColor, + // // textStyle: TextStyle( + // // color: CustomMaterialColor(240, 240, 240) + // // .mdColor, + // // ), + // // iconColor: CustomMaterialColor(240, 240, 240) + // // .mdColor), + // // IconsButton( + // // onPressed: () {}, + // // text: 'Purchase', + // // iconData: Icons.done, + // // color: Colors.green, + // // textStyle: TextStyle( + // // color: CustomMaterialColor(240, 240, 240) + // // .mdColor, + // // ), + // // iconColor: CustomMaterialColor(240, 240, 240) + // // .mdColor), + // // ], + // // ); }, child: Container( - decoration: BoxDecoration( - border: Border.all( - color: - CustomMaterialColor(240, 240, 240) - .mdColor, - width: 2), - borderRadius: const BorderRadius.all( - Radius.circular(10))), + decoration: BoxDecoration(border: Border.all(color: CustomMaterialColor(240, 240, 240).mdColor, width: 2), borderRadius: const BorderRadius.all(Radius.circular(10))), margin: const EdgeInsets.all(4), height: 120, child: ClipRRect( - borderRadius: const BorderRadius.all( - Radius.circular(10)), + borderRadius: const BorderRadius.all(Radius.circular(10)), child: Container( decoration: BoxDecoration( image: DecorationImage( - colorFilter: const ColorFilter.mode( - Colors.black26, BlendMode.darken), + colorFilter: const ColorFilter.mode(Colors.black26, BlendMode.darken), fit: BoxFit.cover, - image: - AssetImage(timeBgAssets[index % 3]), + image: AssetImage(timeBgAssets[index % 3]), )), child: BackdropFilter( - filter: ImageFilter.blur( - sigmaX: 2, sigmaY: 2), + filter: ImageFilter.blur(sigmaX: 2, sigmaY: 2), child: Row( children: [ Expanded( flex: 6, child: Container( - padding: - EdgeInsets.only(left: 20), + padding: EdgeInsets.only(left: 20), // color: Colors.red, - margin: const EdgeInsets.only( - top: 4, left: 4, bottom: 4), + margin: const EdgeInsets.only(top: 4, left: 4, bottom: 4), child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - data?[index % data.length] - .name ?? - "Unknown Seller", + data?[index].name ?? "Unknown Seller", textAlign: TextAlign.start, - overflow: - TextOverflow.ellipsis, - style: const TextStyle( - fontSize: 24), + overflow: TextOverflow.ellipsis, + style: const TextStyle(fontSize: 24), ), Row( children: [ - Icon(Icons.star, - color: - CustomMaterialColor( - 240, - 240, - 240) - .mdColor, - size: 16), - Icon(Icons.star, - color: - CustomMaterialColor( - 240, - 240, - 240) - .mdColor, - size: 16), - Icon(Icons.star, - color: - CustomMaterialColor( - 240, - 240, - 240) - .mdColor, - size: 16), - Icon(Icons.star_half, - color: - CustomMaterialColor( - 240, - 240, - 240) - .mdColor, - size: 16), - Icon(Icons.star_border, - color: - CustomMaterialColor( - 240, - 240, - 240) - .mdColor, - size: 16), + Icon( + Icons.star, + color: Colors.yellow, + size: 16, + ), + Icon( + Icons.star, + color: Colors.yellow, + size: 16, + ), + Icon( + Icons.star, + color: Colors.yellow, + size: 16, + ), + Icon( + Icons.star_half, + color: Colors.yellow, + size: 16, + ), + Icon( + Icons.star_border, + color: Colors.yellow, + size: 16, + ), ], ), Expanded( child: Column( - mainAxisAlignment: - MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.end, children: [ Text( "$startTimeFmt - $endTimeFmt", - textAlign: - TextAlign.start, - overflow: TextOverflow - .ellipsis, - style: TextStyle( - fontSize: 16), + textAlign: TextAlign.start, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 16), ), ], ), @@ -502,8 +548,7 @@ class _BuyScreenState extends State { Expanded( flex: 4, child: Container( - padding: - EdgeInsets.only(right: 15), + padding: EdgeInsets.only(right: 15), child: Text( '\$${price}', textAlign: TextAlign.end, @@ -521,7 +566,12 @@ class _BuyScreenState extends State { } else if (snapshot.hasError) { return Text("${snapshot.error}"); } - return CircularProgressIndicator(); + return const SizedBox( + width: 20, + child: const Center( + child: CircularProgressIndicator(), + ), + ); }, ); }), @@ -532,7 +582,7 @@ class _BuyScreenState extends State { } } - Future showSheet(BuildContext context, int index) { + Future showSheet(BuildContext context, int index, String? sellerName, double SellerPrice, DateTime startTime, DateTime endTime, String sellerLocation) { return showModalBottomSheet( backgroundColor: Colors.transparent, context: context, @@ -546,7 +596,7 @@ class _BuyScreenState extends State { topLeft: Radius.circular(15), topRight: Radius.circular(15), ), - color: Colors.black, + color: Colors.white, ), child: Column( children: [ @@ -560,7 +610,7 @@ class _BuyScreenState extends State { child: Text( "Transaction Details", style: const TextStyle( - color: Colors.white, + color: Colors.black, fontFamily: 'Proxima', fontSize: 20, fontWeight: FontWeight.w700, @@ -641,13 +691,75 @@ class _BuyScreenState extends State { Expanded( child: Container( color: Colors.white, + child: Column( + children: [ + ListTile( + leading: const Icon( + Icons.person, + color: Colors.blue, + ), + title: Text( + sellerName!, + style: const TextStyle( + color: Colors.black, + fontFamily: 'Proxima', + fontSize: 18, + ), + ), + ), + ListTile( + leading: const Icon( + Icons.calendar_today, + color: Colors.red, + ), + title: Text( + "${dateFormat.format(startTime)} - ${dateFormat.format(endTime)}", + style: const TextStyle( + color: Colors.black, + fontFamily: 'Proxima', + fontSize: 18, + ), + ), + ), + ListTile( + leading: const Icon( + Icons.attach_money, + color: Colors.green, + ), + title: Text( + SellerPrice.toString(), + style: const TextStyle( + color: Colors.black, + fontFamily: 'Proxima', + fontSize: 18, + ), + ), + ), + ListTile( + leading: const Icon( + Icons.map, + color: Colors.orange, + ), + title: Text( + sellerLocation, + style: const TextStyle( + color: Colors.black, + fontFamily: 'Proxima', + fontSize: 18, + ), + ), + ), + ], + ), ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton( - onPressed: () {}, + onPressed: () { + Navigator.pop(context); + }, child: Text( "Cancel", style: const TextStyle( diff --git a/lib/sell.dart b/lib/sell.dart index 1886af5..882cb39 100644 --- a/lib/sell.dart +++ b/lib/sell.dart @@ -19,6 +19,8 @@ class SellScreen extends StatefulWidget { } Map values = { + 'Busch Dining Hall': false, + 'Woody\'s Cafe': false, 'Brower Dining Hall': false, 'Cafe West': false, 'Livingston Dining Hall': false, @@ -47,7 +49,10 @@ class _SellScreenState extends State { return Scaffold( body: Column(children: [ Container( - padding: EdgeInsets.only(top: 10, left: 10), + padding: EdgeInsets.only( + top: 35, + left: 10, + ), child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ @@ -111,29 +116,29 @@ class _SellScreenState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ InkWell( - onTap: () { - DatePicker.showDateTimePicker(context, - showTitleActions: true, - minTime: DateTime.now(), - onChanged: (date) {}, onConfirm: (date) { + onTap: () async { + final TimeOfDay? picked = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime(startTimeTime), + ); + if (picked != null) { setState(() { - endTimeTime = date; - endTime = dateFormat.format(date); + startTimeTime = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, picked.hour, picked.minute); + startTime = "${startTimeTime.hour}:${startTimeTime.minute}${(is24HoursFormat) ? "" : ((startTimeTime.hour > 12) ? "PM" : "AM")}"; }); - }, - currentTime: DateTime.now(), - locale: LocaleType.en); + } + // DatePicker.showDateTimePicker(context, showTitleActions: true, minTime: DateTime.now(), onChanged: (date) {}, onConfirm: (date) { + // setState(() { + // startTimeTime = date; + // startTime = dateFormat.format(date); + // }); + // }, currentTime: DateTime.now(), locale: LocaleType.en); }, child: Container( padding: EdgeInsets.all(4), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), - border: Border.all( - width: 2, - color: CustomMaterialColor(240, 240, 240) - .mdColor)), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0), border: Border.all(width: 2, color: CustomMaterialColor(240, 240, 240).mdColor)), child: Text( - endTime, + startTime, style: TextStyle( fontSize: 24, ), @@ -145,29 +150,34 @@ class _SellScreenState extends State { style: TextStyle(fontSize: 20), ), InkWell( - onTap: () { - DatePicker.showDateTimePicker(context, - showTitleActions: true, - minTime: DateTime.now(), - onChanged: (date) {}, onConfirm: (date) { + onTap: () async { + final TimeOfDay? picked = await showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime(endTimeTime), + ); + if (picked != null) { setState(() { - startTimeTime = date; - startTime = dateFormat.format(date); + endTimeTime = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day, picked.hour, picked.minute); + endTime = endTimeTime.hour.toString() + ":" + endTimeTime.minute.toString() + ((is24HoursFormat) ? "" : ((endTimeTime.hour > 12) ? "PM" : "AM")); }); - }, - currentTime: DateTime.now(), - locale: LocaleType.en); + } + // DatePicker.showDateTimePicker(context, + // showTitleActions: true, + // minTime: DateTime.now(), + // onChanged: (date) {}, onConfirm: (date) { + // setState(() { + // endTimeTime = date; + // endTime = dateFormat.format(date); + // }); + // }, + // currentTime: DateTime.now(), + // locale: LocaleType.en); }, child: Container( padding: EdgeInsets.all(4), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), - border: Border.all( - width: 2, - color: CustomMaterialColor(240, 240, 240) - .mdColor)), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0), border: Border.all(width: 2, color: CustomMaterialColor(240, 240, 240).mdColor)), child: Text( - startTime, + endTime, style: TextStyle( fontSize: 24, ), @@ -192,7 +202,7 @@ class _SellScreenState extends State { size: 40, ), const Text( - 'Money', + 'Cost', style: TextStyle( fontSize: 30, ), @@ -207,25 +217,18 @@ class _SellScreenState extends State { children: [ Container( padding: EdgeInsets.all(4), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), - border: Border.all( - width: 2, - color: CustomMaterialColor(240, 240, 240) - .mdColor)), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0), border: Border.all(width: 2, color: CustomMaterialColor(240, 240, 240).mdColor)), child: SizedBox( width: 150, child: TextField( keyboardType: TextInputType.number, textAlign: TextAlign.center, - style: - TextStyle(color: Colors.white, fontSize: 24), + style: TextStyle(color: Colors.white, fontSize: 24), controller: priceController, decoration: InputDecoration( contentPadding: EdgeInsets.zero, hintText: 'Price', - hintStyle: TextStyle( - color: Colors.white24, fontSize: 24), + hintStyle: TextStyle(color: Colors.white24, fontSize: 24), ), ), ), @@ -249,13 +252,7 @@ class _SellScreenState extends State { if (value == true) locations.add(key); }); if (user != null) { - Seller seller = Seller( - user.displayName, - user.uid, - locations, - TimeRange(Timestamp.fromDate(startTimeTime), - Timestamp.fromDate(endTimeTime)), - double.parse(priceController.text)); + Seller seller = Seller(user.displayName, user.uid, locations, TimeRange(Timestamp.fromDate(startTimeTime), Timestamp.fromDate(endTimeTime)), double.parse(priceController.text)); addSeller(seller); } },