subida de horarios
This commit is contained in:
@@ -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),
|
||||||
]),
|
]),
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -21,7 +28,7 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
|||||||
bool jornadaContinuaLunes = false;
|
bool jornadaContinuaLunes = false;
|
||||||
|
|
||||||
Map<String, Schedule> horarios = {
|
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),
|
"Martes": Schedule(false, false, null, null, null, null),
|
||||||
"Miercoles": Schedule(false, false, null, null, null, null),
|
"Miercoles": Schedule(false, false, null, null, null, null),
|
||||||
"Jueves": 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),
|
"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,49 +79,32 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
|||||||
label: 'Horario'),
|
label: 'Horario'),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: horarios.entries.map<Widget>(
|
children: [
|
||||||
(entry) {
|
const Divider(
|
||||||
return SchedulePicker(
|
height: 5,
|
||||||
name: entry.key,
|
),
|
||||||
schedule: entry.value,
|
Column(
|
||||||
);
|
children: horarios.entries.map<Widget>(
|
||||||
},
|
(entry) {
|
||||||
).toList(),
|
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);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user