From 77cfb5cd4af8b8e740aab993b8fbfae1dac45605 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:02:09 -0500 Subject: [PATCH] citas con dia --- lib/src/models/event_model.dart | 5 +- lib/src/screens/calendar.dart | 93 +++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/lib/src/models/event_model.dart b/lib/src/models/event_model.dart index eaf29d2..e585f9f 100644 --- a/lib/src/models/event_model.dart +++ b/lib/src/models/event_model.dart @@ -30,18 +30,19 @@ class EventoService { } } -Future> getByProId() async { +Future> getByProId(String day) async { try { var snapshot = await FirebaseFirestore.instance .collection('services') .where('profesional_id', isEqualTo: uid) + .where('day', isEqualTo: day.toString()) .get(); List eventos = []; for (var element in snapshot.docs) { eventos.add(Event.fromJson(element.data())); } - print('Error getByProId $eventos'); + print('Error getByProId 1 $eventos'); return eventos; } catch (e) { print('Error getByProId $e'); diff --git a/lib/src/screens/calendar.dart b/lib/src/screens/calendar.dart index f12c1dc..da9ddba 100644 --- a/lib/src/screens/calendar.dart +++ b/lib/src/screens/calendar.dart @@ -78,31 +78,39 @@ class _CalendarScreenState extends State { }, label: 'Calendario', ), - body: Container( - child: Column( - children: [ - Container( - color: const Color.fromARGB(255, 224, 247, 255), - child: TableCalendar( - locale: 'es_MX', - firstDay: DateTime.utc(2010, 10, 16), - lastDay: lastDay, - focusedDay: today, - availableGestures: AvailableGestures.all, - onDaySelected: _onDaySelected, - selectedDayPredicate: (day) => isSameDay(day, today), - calendarFormat: _calendarFormat, - onFormatChanged: _onFormatChange, - availableCalendarFormats: const { - CalendarFormat.month: 'Mes', - CalendarFormat.week: 'Semana', - CalendarFormat.twoWeeks: '2 Semanas', - }, - ), + body: Column( + children: [ + Container( + color: const Color.fromARGB(255, 224, 247, 255), + child: TableCalendar( + locale: 'es_MX', + firstDay: DateTime.utc(2010, 10, 16), + lastDay: lastDay, + focusedDay: today, + availableGestures: AvailableGestures.all, + onDaySelected: _onDaySelected, + selectedDayPredicate: (day) => isSameDay(day, today), + calendarFormat: _calendarFormat, + onFormatChanged: _onFormatChange, + availableCalendarFormats: const { + CalendarFormat.month: 'Mes', + CalendarFormat.week: 'Semana', + CalendarFormat.twoWeeks: '2 Semanas', + }, ), - _eventList() - ], - ), + ), + SizedBox( + width: double.infinity, + child: Padding( + padding: + const EdgeInsets.symmetric(horizontal: 15, vertical: 8), + child: Text(DateFormat('dd MMMM yyyy', 'es').format(today)), + )), + const Divider( + height: 0, + ), + _eventList() + ], ), floatingActionButton: FloatingActionButton( onPressed: _showDialog, @@ -271,7 +279,8 @@ class _CalendarScreenState extends State { Widget _eventList() { return FutureBuilder( - future: getByProId(), + future: + getByProId('${DateFormat("yyyy-MM-dd 00:00:00.000").format(today)}Z'), builder: (BuildContext context, AsyncSnapshot> snapshot) { if (!snapshot.hasData) { return const Text('No tiene citas'); @@ -286,15 +295,43 @@ class _CalendarScreenState extends State { } if (eventos.isEmpty) { - return const Text('No tiene citas'); + return const Center(child: Text('No tienes citas')); } return Column( children: [ ...eventos.map( (e) => ListTile( leading: Text('${e.range1Hour1}'), - title: Text('${e.title}'), - trailing: Text('${e.day}'), + title: RichText( + text: TextSpan( + children: [ + TextSpan( + text: '${e.title}, ', + style: const TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + TextSpan( + text: DateFormat('dd MMMM yyyy', 'es') + .format(DateTime.parse(e.day!)), + style: TextStyle( + color: Colors.grey[400], + fontSize: 16, + ), + ), + ], + ), + ), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('${e.description}'), + Text('${e.description}'), + ], + ), + trailing: const Icon(Icons.keyboard_arrow_right), ), ), ],