This commit is contained in:
Felipe
2024-01-06 13:59:44 -05:00
parent a7db9d986d
commit 7977a9be24
5 changed files with 72 additions and 133 deletions
+44 -105
View File
@@ -29,15 +29,14 @@ import 'package:prosappco/src/presentation/widgets/shared/drawer_menu.dart';
import 'package:prosappco/src/presentation/widgets/shared/primary_button.dart';
import 'package:prosappco/src/presentation/widgets/shared/warning_snackbar.dart';
import 'package:prosappco/src/providers/user_provider.dart';
import 'package:prosappco/src/utils/time_of_day_extension.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
class ServiceScreen extends StatefulWidget {
final DateTime? fechaSeleccionada;
final TimeOfDay? horaSeleccionada;
const ServiceScreen(
{super.key, this.fechaSeleccionada, this.horaSeleccionada});
const ServiceScreen({
super.key,
});
@override
State<ServiceScreen> createState() => _ServiceScreenState();
@@ -95,6 +94,10 @@ class _ServiceScreenState extends State<ServiceScreen> {
late final FirebaseAuth _auth;
final _nameController = TextEditingController();
DateTime? fechaSeleccionada;
TimeOfDay? horaSeleccionada;
Professional? profesionalSeleccionado;
@override
void initState() {
super.initState();
@@ -105,9 +108,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
_auth = FirebaseAuth.instance;
print('jurgo 1 ${widget.fechaSeleccionada}');
print('jurgo 2 ${widget.horaSeleccionada}');
final currentUser = _auth.currentUser;
if (currentUser != null && currentUser.displayName != null) {
@@ -507,11 +507,15 @@ class _ServiceScreenState extends State<ServiceScreen> {
},
),
);
if (datos != null) {
Professional? profesional = datos[0];
ubicacion = datos[1];
fechaSeleccionada = datos[0];
horaSeleccionada = datos[1];
Professional? profesional = datos[2];
profesionalSeleccionado = profesional;
if (profesional != null) {
ubicacion = profesional.ubicacion;
if (mounted) {
setState(() {
_profesionalController.text =
@@ -619,12 +623,10 @@ class _ServiceScreenState extends State<ServiceScreen> {
},
),
),
widget.fechaSeleccionada == null &&
widget.horaSeleccionada == null
fechaSeleccionada == null && horaSeleccionada == null
? const SizedBox()
: const SizedBox(height: 15),
widget.fechaSeleccionada == null &&
widget.horaSeleccionada == null
fechaSeleccionada == null && horaSeleccionada == null
? const SizedBox()
: Row(
children: [
@@ -635,71 +637,40 @@ class _ServiceScreenState extends State<ServiceScreen> {
prefixIcon: Icon(Icons.calendar_month),
hintText: 'Fecha',
),
// controller: TextEditingController(
// text: _selectedDate == null
// ? ''
// : formatter.format(_selectedDate!),
// ),
controller: TextEditingController(
text: widget.fechaSeleccionada == null
text: fechaSeleccionada == null
? ''
: formatter
.format(widget.fechaSeleccionada!),
: formatter.format(fechaSeleccionada!),
),
// onTap: () {
// if (_profesionalController
// .text.isNotEmpty) {
// _selectDateAndTime(context);
// } else {
// WarningSnackbar.show(
// title: 'Selecciona un profesional',
// message:
// 'Selecciona un profesional antes de elegir la fecha y la hora de la cita.',
// backgroundColor: Colors.orange,
// );
// }
// },
),
),
Expanded(
child: TextFormField(
// onTap: () {
// if (_profesionalController.text.isNotEmpty) {
// _selectDateAndTime(context);
// } else {
// WarningSnackbar.show(
// title: 'Selecciona un profesional',
// message:
// 'Selecciona un profesional antes de elegir la fecha y la hora de la cita.',
// backgroundColor: Colors.orange);
// }
// },
readOnly: true,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.watch_later_outlined),
hintText: 'Hora',
),
// controller: TextEditingController(
// text: _selectedTime == null
// ? ''
// : ' ${_selectedTime!.format(context)}',
// ),
controller: TextEditingController(
text: widget.horaSeleccionada == null
text: horaSeleccionada == null
? ''
: ' ${widget.horaSeleccionada!.format(context)}',
: ' ${horaSeleccionada!.format(context)}',
),
))
],
),
const SizedBox(height: 15),
TextFormField(
controller: _observacionController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.message_outlined),
hintText: 'Observaciones',
),
),
fechaSeleccionada == null && horaSeleccionada == null
? const SizedBox()
: const SizedBox(height: 15),
fechaSeleccionada == null && horaSeleccionada == null
? const SizedBox()
: TextFormField(
controller: _observacionController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.message_outlined),
hintText: 'Observaciones',
),
),
const SizedBox(height: 20),
Center(
child: PrimaryButton(
@@ -724,25 +695,25 @@ class _ServiceScreenState extends State<ServiceScreen> {
);
} else {
try {
final DateTime combinedDate = DateTime(
_selectedDate!.year,
_selectedDate!.month,
_selectedDate!.day,
_selectedTime!.hour,
_selectedTime!.minute,
DateTime time1 = DateTime(
fechaSeleccionada!.year,
fechaSeleccionada!.month,
fechaSeleccionada!.day,
horaSeleccionada!.hour,
horaSeleccionada!.minute,
);
DateTime time2 = combinedDate.add(
const Duration(hours: 2),
);
DateTime time2 =
time1.add(const Duration(hours: 2));
UserModel.getUser(uid.toString()).then((value) {
eventoService
.createEvent(
value.name,
_observacionController.text,
'$_selectedDate',
'$combinedDate',
fechaSeleccionada.toString().substring(0,
fechaSeleccionada.toString().length - 1),
'$time1',
'$time2',
professionalId,
ubicacion,
@@ -780,7 +751,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
WarningSnackbar.show(
title: 'Llena todos los campos',
message:
'Asegurate de llenar todos los campos antes de solicitar un servicio.',
'Asegurate de llenar todos los campos antes de solicitar un servicio. $e',
);
}
}
@@ -995,38 +966,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
}
}
Future<void> _selectDate(BuildContext context) async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: now,
firstDate: now,
lastDate: DateTime(now.year + 1),
);
if (picked != null && picked != _selectedDate) {
if (mounted) {
setState(() {
_selectedDate = picked;
});
}
}
}
Future<void> _selectTime(BuildContext context) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if (pickedTime != null) {
if (mounted) {
setState(() {
_selectedTime = pickedTime;
});
}
}
}
Future<List<DocumentSnapshot<Map<String, dynamic>>>> getUsersWithActiveStatus(
String serviceType) async {
dynamic querySnapshot;