diff --git a/lib/src/components/schedule_picker.dart b/lib/src/components/schedule_picker.dart index d12113a..4d76ee4 100644 --- a/lib/src/components/schedule_picker.dart +++ b/lib/src/components/schedule_picker.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:prosappco/src/components/primary_btn.dart'; typedef TimeCallback = void Function(TimeOfDay? pickedTime); @@ -62,7 +63,7 @@ class _SchedulePickerState extends State { datePicker(widget.schedule.range1Hour2, (pickedTime) => widget.schedule.range1Hour2 = pickedTime), ]), - ) + ), ]; } diff --git a/lib/src/screens/horario.dart b/lib/src/screens/horario.dart index 7299e5b..3e5a05c 100644 --- a/lib/src/screens/horario.dart +++ b/lib/src/screens/horario.dart @@ -1,5 +1,9 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; +import 'package:prosappco/src/authentication/authentication_repository.dart'; import 'package:prosappco/src/components/pop_appbar.dart'; +import 'package:prosappco/src/components/primary_btn.dart'; import '../components/schedule_picker.dart'; @@ -11,6 +15,9 @@ class HorarioScreen extends StatefulWidget { } class _HorarioScreenState extends State { + late final FirebaseAuth _auth; + final uid = AuthenticationRepository.instance.getCurrentUserUid(); + bool lunesValue = false; bool martesValue = false; bool miercolesValue = false; @@ -21,7 +28,7 @@ class _HorarioScreenState extends State { bool jornadaContinuaLunes = false; Map horarios = { - "Lunes": Schedule(false, false, null, null, null , null), + "Lunes": Schedule(false, false, null, null, null, null), "Martes": Schedule(false, false, null, null, null, null), "Miercoles": Schedule(false, false, null, null, null, null), "Jueves": Schedule(false, false, null, null, null, null), @@ -30,6 +37,37 @@ class _HorarioScreenState extends State { "Domingo": Schedule(false, false, null, null, null, null), }; + Future updateHorario() async { + try { + Map horariosMap = {}; + horarios.forEach((key, value) { + horariosMap[key] = { + 'habilitado': value.habilitado, + 'jornadaContinua': value.jornadaContinua, + 'range1Hour1': value.range1Hour1 != null + ? value.range1Hour1!.format(context).toString() + : null, + 'range1Hour2': value.range1Hour2 != null + ? value.range1Hour2!.format(context).toString() + : null, + 'range2Hour1': value.range2Hour1 != null + ? value.range2Hour1!.format(context).toString() + : null, + 'range2Hour2': value.range2Hour2 != null + ? value.range2Hour2!.format(context).toString() + : null, + }; + }); + + await FirebaseFirestore.instance.collection('users').doc(uid).update({ + 'horario': horariosMap, + }); + print('Horarios actualizados correctamente'); + } catch (e) { + print('Error al actualizar el horario: $e'); + } + } + @override Widget build(BuildContext context) { return SafeArea( @@ -41,49 +79,32 @@ class _HorarioScreenState extends State { label: 'Horario'), body: SingleChildScrollView( child: Column( - children: horarios.entries.map( - (entry) { - return SchedulePicker( - name: entry.key, - schedule: entry.value, - ); - }, - ).toList(), + children: [ + const Divider( + height: 5, + ), + Column( + children: horarios.entries.map( + (entry) { + return SchedulePicker( + name: entry.key, + schedule: entry.value, + ); + }, + ).toList(), + ), + Padding( + padding: const EdgeInsets.only(top: 100, bottom: 30), + child: PrimaryButtom( + onPressed: () async { + updateHorario(); + }, + label: 'Guardar'), + ) + ], ), ), ), ); } - - customSwitch(String text, bool switchValue, ValueChanged onChanged) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 30), - child: SizedBox( - height: 40, - child: Row( - children: [ - Expanded( - child: Text( - text, - style: const TextStyle( - fontSize: 15, - color: Colors.black, - ), - )), - Transform.scale( - scale: 1.2, - child: Switch( - value: switchValue, - onChanged: (bool newValue) { - setState(() { - onChanged(newValue); - }); - }, - ), - ), - ], - ), - ), - ); - } }