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:prosappco/src/components/primary_btn.dart';
typedef TimeCallback = void Function(TimeOfDay? pickedTime);
@@ -62,7 +63,7 @@ class _SchedulePickerState extends State<SchedulePicker> {
datePicker(widget.schedule.range1Hour2,
(pickedTime) => widget.schedule.range1Hour2 = pickedTime),
]),
)
),
];
}
+62 -41
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: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<HorarioScreen> {
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<HorarioScreen> {
bool jornadaContinuaLunes = false;
Map<String, Schedule> 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<HorarioScreen> {
"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
Widget build(BuildContext context) {
return SafeArea(
@@ -41,49 +79,32 @@ class _HorarioScreenState extends State<HorarioScreen> {
label: 'Horario'),
body: SingleChildScrollView(
child: Column(
children: horarios.entries.map<Widget>(
(entry) {
return SchedulePicker(
name: entry.key,
schedule: entry.value,
);
},
).toList(),
children: [
const Divider(
height: 5,
),
Column(
children: horarios.entries.map<Widget>(
(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<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);
});
},
),
),
],
),
),
);
}
}