From d00c9cb5b94a335ca7737e10f0c29d2af8500a4f Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Sun, 26 Feb 2023 13:46:30 -0500 Subject: [PATCH] DateTime on sell menu fixes --- lib/sell.dart | 281 ++++++++++++++++++++++++-------------------------- pubspec.lock | 8 ++ pubspec.yaml | 1 + 3 files changed, 146 insertions(+), 144 deletions(-) diff --git a/lib/sell.dart b/lib/sell.dart index 1e0392a..761733e 100644 --- a/lib/sell.dart +++ b/lib/sell.dart @@ -4,7 +4,9 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:currency_text_input_formatter/currency_text_input_formatter.dart'; +import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:ruswipeshare/auth_gate.dart'; +import 'package:intl/intl.dart'; import 'package:ruswipeshare/meetings.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; @@ -29,6 +31,7 @@ Map values = { }; class _SellScreenState extends State { + DateFormat dateFormat = DateFormat("HH:mm a"); String startTime = 'Start Time'; DateTime startTimeTime = DateTime.now(); String endTime = 'End Time'; @@ -43,160 +46,150 @@ class _SellScreenState extends State { resizeToAvoidBottomInset: true, body: Padding( padding: const EdgeInsets.fromLTRB(0, 8, 0, 0), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Icon(Icons.store_mall_directory, color: Colors.red), - Text('Place'), - ], - ), - ConstrainedBox( - constraints: const BoxConstraints.expand(height: 250), - child: ListView.builder( - itemCount: values.length, - itemBuilder: (context, index) => CheckboxListTile( - title: Text(values.keys.elementAt(index)), - value: values.values.elementAt(index), - onChanged: (bool? value) { - setState(() { - values[values.keys.elementAt(index)] = value!; - }); - }, - ), + child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Icon(Icons.store_mall_directory, color: Colors.red), + Text('Place'), + ], + ), + ConstrainedBox( + constraints: const BoxConstraints.expand(height: 250), + child: ListView.builder( + itemCount: values.length, + itemBuilder: (context, index) => CheckboxListTile( + title: Text(values.keys.elementAt(index)), + value: values.values.elementAt(index), + onChanged: (bool? value) { + setState(() { + values[values.keys.elementAt(index)] = value!; + }); + }, ), ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Icon(Icons.access_time, color: Colors.red), - Text('Time'), - ], - ), - SizedBox( - height: 100, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text( - startTime, - style: TextStyle(fontSize: 35), - ), - Text( - "to", - style: TextStyle(fontSize: 20), - ), - Text( - endTime, - style: TextStyle(fontSize: 35), - ), - ], - ), - ), - Row( + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Icon(Icons.access_time, color: Colors.red), + Text('Time'), + ], + ), + SizedBox( + height: 100, + child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - ElevatedButton( - onPressed: () async { - final TimeOfDay? picked = await showTimePicker( - context: context, - initialTime: TimeOfDay.fromDateTime(startTimeTime), - ); - if (picked != null && - picked != TimeOfDay.fromDateTime(startTimeTime)) { - setState(() { - startTimeTime = DateTime.fromMicrosecondsSinceEpoch( - picked.hour * 60 * 60 * 1000000 + - picked.minute * 60 * 1000000, - isUtc: true); - startTime = startTimeTime.hour.toString() + - ":" + - startTimeTime.minute.toString() + - ((is24HoursFormat) - ? "" - : ((startTimeTime.hour > 12) ? "PM" : "AM")); - }); - } - }, - child: const Text('Select Start Time'), + Text( + startTime, + style: TextStyle(fontSize: 35), ), - ElevatedButton( - onPressed: () async { - final TimeOfDay? picked = await showTimePicker( - context: context, - initialTime: TimeOfDay.fromDateTime(endTimeTime), - ); - if (picked != null && - picked != TimeOfDay.fromDateTime(endTimeTime)) { - setState(() { - endTimeTime = DateTime.fromMicrosecondsSinceEpoch( - picked.hour * 60 * 60 * 1000000 + - picked.minute * 60 * 1000000, - isUtc: true); - endTime = endTimeTime.hour.toString() + - ":" + - endTimeTime.minute.toString() + - ((is24HoursFormat) - ? "" - : ((endTimeTime.hour > 12) ? "PM" : "AM")); - }); - } - }, - child: const Text('Select End Time'), + Text( + "to", + style: TextStyle(fontSize: 20), + ), + Text( + endTime, + style: TextStyle(fontSize: 35), ), ], ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Icon(Icons.attach_money, color: Colors.red), - Text('Cost'), - ], - ), - SizedBox( - width: 150, - child: TextField( - keyboardType: TextInputType.number, - textAlign: TextAlign.center, - style: TextStyle(color: Colors.white, fontSize: 30), - controller: priceController, - decoration: InputDecoration( - border: OutlineInputBorder(), - hintText: 'Price', - hintStyle: TextStyle(color: Colors.white24, fontSize: 30), - ), - )), - ElevatedButton( - onPressed: () { - List locations = []; - User? user = auth.currentUser; - values.forEach((key, value) { - if (value == true) locations.add(key); - }); - if (user != null) { - Seller seller = Seller( - "", - user.uid, - locations, - TimeRange(Timestamp.fromDate(startTimeTime), - Timestamp.fromDate(endTimeTime)), - double.parse(priceController.text)); - - print("SIFSIFISFHJIS"); - print(seller); - addSeller(seller); - } - }, - style: ButtonStyle( - backgroundColor: - MaterialStateColor.resolveWith((states) => Colors.blue), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ElevatedButton( + onPressed: () async { + DatePicker.showDateTimePicker(context, showTitleActions: true, minTime: DateTime.now(), onChanged: (date) { + print('change $date'); + }, onConfirm: (date) { + setState(() { + startTimeTime = date; + startTime = dateFormat.format(date); + print('confirm $date'); + }); + }, currentTime: DateTime.now(), locale: LocaleType.en); + // final TimeOfDay? picked = await showTimePicker( + // context: context, + // initialTime: TimeOfDay.fromDateTime(startTimeTime), + // ); + // if (picked != null && picked != TimeOfDay.fromDateTime(startTimeTime)) { + // setState(() { + // startTimeTime = DateTime.fromMicrosecondsSinceEpoch(picked.hour * 60 * 60 * 1000000 + picked.minute * 60 * 1000000, isUtc: true); + // startTime = startTimeTime.hour.toString() + ":" + startTimeTime.minute.toString() + ((is24HoursFormat) ? "" : ((startTimeTime.hour > 12) ? "PM" : "AM")); + // }); + // } + }, + child: const Text('Select Start Time'), + ), + ElevatedButton( + onPressed: () async { + DatePicker.showDateTimePicker(context, showTitleActions: true, minTime: DateTime.now(), onChanged: (date) { + print('change $date'); + }, onConfirm: (date) { + setState(() { + endTimeTime = date; + endTime = dateFormat.format(date); + print('confirm $date'); + }); + }, currentTime: DateTime.now(), locale: LocaleType.en); + // final TimeOfDay? picked = await showTimePicker( + // context: context, + // initialTime: TimeOfDay.fromDateTime(endTimeTime), + // ); + // if (picked != null && picked != TimeOfDay.fromDateTime(endTimeTime)) { + // setState(() { + // endTimeTime = DateTime.fromMicrosecondsSinceEpoch(picked.hour * 60 * 60 * 1000000 + picked.minute * 60 * 1000000, isUtc: true); + // endTime = endTimeTime.hour.toString() + ":" + endTimeTime.minute.toString() + ((is24HoursFormat) ? "" : ((endTimeTime.hour > 12) ? "PM" : "AM")); + // }); + // } + }, + child: const Text('Select End Time'), + ), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Icon(Icons.attach_money, color: Colors.red), + Text('Cost'), + ], + ), + SizedBox( + width: 150, + child: TextField( + keyboardType: TextInputType.number, + textAlign: TextAlign.center, + style: TextStyle(color: Colors.white, fontSize: 30), + controller: priceController, + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Price', + hintStyle: TextStyle(color: Colors.white24, fontSize: 30), ), - child: const Text('Submit Sell Request'), ), - ], - ), + ), + ElevatedButton( + onPressed: () { + List locations = []; + User? user = auth.currentUser; + values.forEach((key, value) { + if (value == true) locations.add(key); + }); + if (user != null) { + Seller seller = Seller("", user.uid, locations, TimeRange(Timestamp.fromDate(startTimeTime), Timestamp.fromDate(endTimeTime)), double.parse(priceController.text)); + print("SIFSIFISFHJIS"); + print(seller); + addSeller(seller); + } + }, + style: ButtonStyle( + backgroundColor: MaterialStateColor.resolveWith((states) => Colors.blue), + ), + child: const Text('Submit Sell Request'), + ), + ]), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 6a8d709..cfd0664 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -254,6 +254,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.5" + flutter_datetime_picker: + dependency: "direct main" + description: + name: flutter_datetime_picker + sha256: "8e695c63c769350e541951227c2775190ec73ceda774a315b1dc9a99d5facfe5" + url: "https://pub.dev" + source: hosted + version: "1.5.1" flutter_dotenv: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index e21b962..9958fd9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: cloud_firestore: any currency_text_input_formatter: ^2.1.9 http: any + flutter_datetime_picker: ^1.5.1 dev_dependencies: flutter_test: