calendario disponibles y ocupados

This commit is contained in:
Felipe
2024-01-06 18:14:35 -05:00
parent 7977a9be24
commit ae932ca582
+130 -84
View File
@@ -6,6 +6,7 @@ import 'package:prosappco/src/components/schedule_picker.dart';
import 'package:prosappco/src/models/event_model.dart'; import 'package:prosappco/src/models/event_model.dart';
import 'package:prosappco/src/models/professional_model.dart'; import 'package:prosappco/src/models/professional_model.dart';
import 'package:prosappco/src/presentation/screens/map/service.dart'; import 'package:prosappco/src/presentation/screens/map/service.dart';
import 'package:prosappco/src/presentation/widgets/shared/warning_snackbar.dart';
import 'package:prosappco/src/utils/time_of_day_utils.dart'; import 'package:prosappco/src/utils/time_of_day_utils.dart';
import 'package:table_calendar/table_calendar.dart'; import 'package:table_calendar/table_calendar.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
@@ -21,7 +22,6 @@ class CalendarProScreen extends StatefulWidget {
class _CalendarProScreenState extends State<CalendarProScreen> { class _CalendarProScreenState extends State<CalendarProScreen> {
final uid = AuthenticationRepository.instance.getCurrentUserUid(); final uid = AuthenticationRepository.instance.getCurrentUserUid();
List<Event>? _events;
EventoService eventoService = EventoService(); EventoService eventoService = EventoService();
CalendarFormat _calendarFormat = CalendarFormat.month; CalendarFormat _calendarFormat = CalendarFormat.month;
@@ -30,6 +30,8 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
late int numDay; late int numDay;
List<Event>? _events;
Map<String, Schedule>? _horarios; Map<String, Schedule>? _horarios;
@override @override
@@ -46,15 +48,16 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
); );
} }
if (_events == null) {
Event.getEventsAllById(widget.professional.id.toString()).then((value) {
setState(() {
_events = value;
});
});
}
today = DateTime.utc(today.year, today.month, today.day); today = DateTime.utc(today.year, today.month, today.day);
numDay = today.weekday; numDay = today.weekday;
if (_events == null) {
Event.getEventsAllByIdStatus(uid ?? "", 'aprobado')
.then((value) => setState(() {
_events = value;
}));
}
} }
void _onDaySelected(DateTime day, DateTime focusedDay) { void _onDaySelected(DateTime day, DateTime focusedDay) {
@@ -80,8 +83,6 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
); );
} }
var events = _events!;
DateTime lastDay = today.add(const Duration(days: 365)); DateTime lastDay = today.add(const Duration(days: 365));
return Scaffold( return Scaffold(
@@ -109,17 +110,6 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
selectedDayPredicate: (day) => isSameDay(day, today), selectedDayPredicate: (day) => isSameDay(day, today),
calendarFormat: _calendarFormat, calendarFormat: _calendarFormat,
onFormatChanged: _onFormatChange, onFormatChanged: _onFormatChange,
// eventLoader: (date) {
// return events
// .where((element) {
// DateTime day = DateTime.parse(element.day);
// return (date.year == day.year &&
// date.month == day.month &&
// date.day == day.day);
// })
// .map((e) => e.description)
// .toList();
// },
availableCalendarFormats: const { availableCalendarFormats: const {
CalendarFormat.month: 'Mes', CalendarFormat.month: 'Mes',
CalendarFormat.week: 'Semana', CalendarFormat.week: 'Semana',
@@ -185,7 +175,7 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
schedule.range2Hour2!, schedule.range2Hour2!,
); );
return rangesItemsa(ranges); return rangesItemList(ranges, _events);
} else { } else {
List<TimeOfDay> ranges1 = TimeOfDayUtils.genRanges( List<TimeOfDay> ranges1 = TimeOfDayUtils.genRanges(
schedule.range1Hour1!, schedule.range1Hour1!,
@@ -197,73 +187,129 @@ class _CalendarProScreenState extends State<CalendarProScreen> {
); );
return [ return [
...rangesItemsa(ranges1), ...rangesItemList(ranges1, _events),
...rangesItemsa(ranges2), ...rangesItemList(ranges2, _events),
]; ];
} }
} }
List<Widget> rangesItemsa(List<TimeOfDay> ranges) { List<Widget> rangesItemList(List<TimeOfDay> ranges, List<Event>? events) {
return ranges return ranges.map((time) {
.map((time) => Card( if (_isHora1Ocupada(time, events)) {
elevation: 4, return Card(
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10), elevation: 4,
shape: RoundedRectangleBorder( margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
borderRadius: BorderRadius.circular(10), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
onTap: () {
WarningSnackbar.show(
title: 'Ocupado',
message: 'Este horário ya se encuentra ocupado',
);
},
contentPadding: const EdgeInsets.all(16),
leading: Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.yellow, Colors.red, Colors.red],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
shape: BoxShape.circle,
), ),
child: ListTile( child: const Center(
onTap: () { child: Icon(
Navigator.pop(context, [today, time, widget.professional]); Icons.access_time,
color: Colors.white,
),
),
),
title: Text(
time.format(context),
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
subtitle: const Text(
'Ocupado',
style: TextStyle(
color: Colors.red, fontSize: 13, fontWeight: FontWeight.bold),
),
trailing: const Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
),
),
);
} else {
return Card(
elevation: 4,
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
onTap: () {
Navigator.pop(context, [today, time, widget.professional]);
},
contentPadding: const EdgeInsets.all(16),
leading: Container(
width: 40,
height: 40,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.green],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
Icons.access_time,
color: Colors.white,
),
),
),
title: Text(
time.format(context),
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
subtitle: const Text(
'Disponible',
style: TextStyle(
color: Colors.green,
fontSize: 13,
fontWeight: FontWeight.bold),
),
trailing: const Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
),
),
);
}
}).toList();
}
// Navigator.pushAndRemoveUntil( bool _isHora1Ocupada(TimeOfDay hora1, List<Event>? events) {
// context, if (events != null) {
// MaterialPageRoute( for (Event event in events) {
// builder: (context) => ServiceScreen( DateTime time1 = DateTime(
// fechaSeleccionada: today, today.year,
// horaSeleccionada: time, today.month,
// professionalSeleccionado: widget.professional, today.day,
// ), hora1.hour,
// ), hora1.minute,
// (route) => false, );
// );
}, if (event.range1Hour1 == time1.toString()) {
contentPadding: const EdgeInsets.all(16), return true;
leading: Container( }
width: 40, }
height: 40, }
decoration: const BoxDecoration( return false;
gradient: LinearGradient(
colors: [Colors.blue, Colors.green],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
Icons.access_time,
color: Colors.white,
),
),
),
title: Text(
time.format(context),
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.bold),
),
subtitle: const Text(
'Disponible',
style: TextStyle(
color: Colors.green,
fontSize: 13,
fontWeight: FontWeight.bold),
),
trailing: const Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
),
),
))
.toList();
} }
} }