DateTime on sell menu fixes

This commit is contained in:
2023-02-26 13:46:30 -05:00
parent e1efe6c237
commit d00c9cb5b9
3 changed files with 146 additions and 144 deletions

View File

@@ -4,7 +4,9 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:currency_text_input_formatter/currency_text_input_formatter.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:ruswipeshare/auth_gate.dart';
import 'package:intl/intl.dart';
import 'package:ruswipeshare/meetings.dart'; import 'package:ruswipeshare/meetings.dart';
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
@@ -29,6 +31,7 @@ Map<String, bool> values = {
}; };
class _SellScreenState extends State<SellScreen> { class _SellScreenState extends State<SellScreen> {
DateFormat dateFormat = DateFormat("HH:mm a");
String startTime = 'Start Time'; String startTime = 'Start Time';
DateTime startTimeTime = DateTime.now(); DateTime startTimeTime = DateTime.now();
String endTime = 'End Time'; String endTime = 'End Time';
@@ -43,160 +46,150 @@ class _SellScreenState extends State<SellScreen> {
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
body: Padding( body: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0), padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
child: Column( child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
mainAxisAlignment: MainAxisAlignment.spaceEvenly, Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
Row( children: const [
mainAxisAlignment: MainAxisAlignment.center, Icon(Icons.store_mall_directory, color: Colors.red),
children: const [ Text('Place'),
Icon(Icons.store_mall_directory, color: Colors.red), ],
Text('Place'), ),
], ConstrainedBox(
), constraints: const BoxConstraints.expand(height: 250),
ConstrainedBox( child: ListView.builder(
constraints: const BoxConstraints.expand(height: 250), itemCount: values.length,
child: ListView.builder( itemBuilder: (context, index) => CheckboxListTile(
itemCount: values.length, title: Text(values.keys.elementAt(index)),
itemBuilder: (context, index) => CheckboxListTile( value: values.values.elementAt(index),
title: Text(values.keys.elementAt(index)), onChanged: (bool? value) {
value: values.values.elementAt(index), setState(() {
onChanged: (bool? value) { values[values.keys.elementAt(index)] = value!;
setState(() { });
values[values.keys.elementAt(index)] = value!; },
});
},
),
), ),
), ),
Row( ),
mainAxisAlignment: MainAxisAlignment.center, Row(
children: const [ mainAxisAlignment: MainAxisAlignment.center,
Icon(Icons.access_time, color: Colors.red), children: const [
Text('Time'), Icon(Icons.access_time, color: Colors.red),
], Text('Time'),
), ],
SizedBox( ),
height: 100, SizedBox(
child: Row( height: 100,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, child: Row(
children: [
Text(
startTime,
style: TextStyle(fontSize: 35),
),
Text(
"to",
style: TextStyle(fontSize: 20),
),
Text(
endTime,
style: TextStyle(fontSize: 35),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
ElevatedButton( Text(
onPressed: () async { startTime,
final TimeOfDay? picked = await showTimePicker( style: TextStyle(fontSize: 35),
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( Text(
onPressed: () async { "to",
final TimeOfDay? picked = await showTimePicker( style: TextStyle(fontSize: 20),
context: context, ),
initialTime: TimeOfDay.fromDateTime(endTimeTime), Text(
); endTime,
if (picked != null && style: TextStyle(fontSize: 35),
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, Row(
children: const [ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
Icon(Icons.attach_money, color: Colors.red), children: [
Text('Cost'), ElevatedButton(
], onPressed: () async {
), DatePicker.showDateTimePicker(context, showTitleActions: true, minTime: DateTime.now(), onChanged: (date) {
SizedBox( print('change $date');
width: 150, }, onConfirm: (date) {
child: TextField( setState(() {
keyboardType: TextInputType.number, startTimeTime = date;
textAlign: TextAlign.center, startTime = dateFormat.format(date);
style: TextStyle(color: Colors.white, fontSize: 30), print('confirm $date');
controller: priceController, });
decoration: InputDecoration( }, currentTime: DateTime.now(), locale: LocaleType.en);
border: OutlineInputBorder(), // final TimeOfDay? picked = await showTimePicker(
hintText: 'Price', // context: context,
hintStyle: TextStyle(color: Colors.white24, fontSize: 30), // initialTime: TimeOfDay.fromDateTime(startTimeTime),
), // );
)), // if (picked != null && picked != TimeOfDay.fromDateTime(startTimeTime)) {
ElevatedButton( // setState(() {
onPressed: () { // startTimeTime = DateTime.fromMicrosecondsSinceEpoch(picked.hour * 60 * 60 * 1000000 + picked.minute * 60 * 1000000, isUtc: true);
List<String> locations = []; // startTime = startTimeTime.hour.toString() + ":" + startTimeTime.minute.toString() + ((is24HoursFormat) ? "" : ((startTimeTime.hour > 12) ? "PM" : "AM"));
User? user = auth.currentUser; // });
values.forEach((key, value) { // }
if (value == true) locations.add(key); },
}); child: const Text('Select Start Time'),
if (user != null) { ),
Seller seller = Seller( ElevatedButton(
"", onPressed: () async {
user.uid, DatePicker.showDateTimePicker(context, showTitleActions: true, minTime: DateTime.now(), onChanged: (date) {
locations, print('change $date');
TimeRange(Timestamp.fromDate(startTimeTime), }, onConfirm: (date) {
Timestamp.fromDate(endTimeTime)), setState(() {
double.parse(priceController.text)); endTimeTime = date;
endTime = dateFormat.format(date);
print("SIFSIFISFHJIS"); print('confirm $date');
print(seller); });
addSeller(seller); }, currentTime: DateTime.now(), locale: LocaleType.en);
} // final TimeOfDay? picked = await showTimePicker(
}, // context: context,
style: ButtonStyle( // initialTime: TimeOfDay.fromDateTime(endTimeTime),
backgroundColor: // );
MaterialStateColor.resolveWith((states) => Colors.blue), // 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<String> 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'),
),
]),
), ),
); );
} }

View File

@@ -254,6 +254,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.5" 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: flutter_dotenv:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@@ -48,6 +48,7 @@ dependencies:
cloud_firestore: any cloud_firestore: any
currency_text_input_formatter: ^2.1.9 currency_text_input_formatter: ^2.1.9
http: any http: any
flutter_datetime_picker: ^1.5.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: