subida de horarios

This commit is contained in:
Juan Felipe Duarte
2023-04-20 12:29:36 -05:00
parent 97bf5324c4
commit 93f00e7399
2 changed files with 64 additions and 42 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:prosappco/src/components/primary_btn.dart';
typedef TimeCallback = void Function(TimeOfDay? pickedTime); typedef TimeCallback = void Function(TimeOfDay? pickedTime);
@@ -62,7 +63,7 @@ class _SchedulePickerState extends State<SchedulePicker> {
datePicker(widget.schedule.range1Hour2, datePicker(widget.schedule.range1Hour2,
(pickedTime) => widget.schedule.range1Hour2 = pickedTime), (pickedTime) => widget.schedule.range1Hour2 = pickedTime),
]), ]),
) ),
]; ];
} }
+51 -30
View File
@@ -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:flutter/material.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/pop_appbar.dart'; import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
import '../components/schedule_picker.dart'; import '../components/schedule_picker.dart';
@@ -11,6 +15,9 @@ class HorarioScreen extends StatefulWidget {
} }
class _HorarioScreenState extends State<HorarioScreen> { class _HorarioScreenState extends State<HorarioScreen> {
late final FirebaseAuth _auth;
final uid = AuthenticationRepository.instance.getCurrentUserUid();
bool lunesValue = false; bool lunesValue = false;
bool martesValue = false; bool martesValue = false;
bool miercolesValue = false; bool miercolesValue = false;
@@ -30,6 +37,37 @@ class _HorarioScreenState extends State<HorarioScreen> {
"Domingo": Schedule(false, false, null, null, null, null), "Domingo": Schedule(false, false, null, null, null, null),
}; };
Future<void> updateHorario() async {
try {
Map<String, dynamic> 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SafeArea( return SafeArea(
@@ -41,6 +79,11 @@ class _HorarioScreenState extends State<HorarioScreen> {
label: 'Horario'), label: 'Horario'),
body: SingleChildScrollView( body: SingleChildScrollView(
child: Column( child: Column(
children: [
const Divider(
height: 5,
),
Column(
children: horarios.entries.map<Widget>( children: horarios.entries.map<Widget>(
(entry) { (entry) {
return SchedulePicker( return SchedulePicker(
@@ -50,40 +93,18 @@ class _HorarioScreenState extends State<HorarioScreen> {
}, },
).toList(), ).toList(),
), ),
), Padding(
), padding: const EdgeInsets.only(top: 100, bottom: 30),
); child: PrimaryButtom(
} onPressed: () async {
updateHorario();
customSwitch(String text, bool switchValue, ValueChanged<bool> 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);
});
}, },
), label: 'Guardar'),
), )
], ],
), ),
), ),
),
); );
} }
} }