|
@@ -1,31 +1,23 @@
|
1
|
1
|
import 'package:flutter/material.dart';
|
2
|
|
-import 'package:fast_med_flutter/ui/pages/add_event.dart';
|
3
|
|
-import 'package:fast_med_flutter/ui/pages/view_event.dart';
|
|
2
|
+import 'package:intl/date_symbol_data_local.dart';
|
4
|
3
|
import 'package:table_calendar/table_calendar.dart';
|
5
|
|
-import 'dart:convert';
|
6
|
|
-import 'package:shared_preferences/shared_preferences.dart';
|
7
|
|
-//import 'package:firebase_core/firebase_core.dart';
|
8
|
|
-import 'dart:async';
|
9
|
|
-import 'package:http/http.dart' as http;
|
10
|
|
-
|
11
|
|
-import 'model/event.dart';
|
12
|
|
-
|
13
|
|
-void main() async{
|
14
|
|
-
|
15
|
|
- var url = 'https://ada.uprrp.edu/~jorge.lopez19/FastMed/API/InsertEvent.php';
|
16
|
|
- WidgetsFlutterBinding.ensureInitialized();
|
17
|
|
- //==final data = await http.post(url, body: {
|
18
|
|
- //"name": name.text,
|
19
|
|
- //"reason": reason.text,
|
20
|
|
- //"date": date.text,
|
21
|
|
- //"time": time.text,
|
22
|
|
- // }
|
23
|
|
- //);
|
24
|
|
- runApp(Calendario());
|
25
|
|
-}
|
26
|
4
|
|
|
5
|
+// Dias de Citas No Disponibles
|
|
6
|
+final Map<DateTime, List> _holidays = {
|
|
7
|
+ DateTime(2020, 11, 6): ['No Hay Citas'],
|
|
8
|
+ DateTime(2020, 11, 3): ['Dia Elecciones'],
|
|
9
|
+ DateTime(2020,12,25): ['Chrismas'],
|
|
10
|
+ DateTime(2020,12,31): ['Despedida del anyo nuevo'],
|
|
11
|
+
|
|
12
|
+};
|
|
13
|
+
|
|
14
|
+//Iniciar la Seccion de las Citas
|
|
15
|
+void main() {
|
|
16
|
+ initializeDateFormatting().then((_) => runApp(Calendario()));
|
|
17
|
+}
|
27
|
18
|
|
28
|
19
|
|
|
20
|
+//Inicio del Area de las Citas Disponibles
|
29
|
21
|
class Calendario extends StatelessWidget {
|
30
|
22
|
@override
|
31
|
23
|
Widget build(BuildContext context) {
|
|
@@ -34,142 +26,331 @@ class Calendario extends StatelessWidget {
|
34
|
26
|
theme: ThemeData(
|
35
|
27
|
primarySwatch: Colors.blue,
|
36
|
28
|
),
|
37
|
|
- home: MyHomePage(),
|
38
|
|
- routes: {
|
39
|
|
- "add_event": (_) => AddEventPage(),
|
40
|
|
- },
|
|
29
|
+ home: MyHomePage(title: 'Citas Disponibles'),
|
41
|
30
|
);
|
42
|
31
|
}
|
43
|
32
|
}
|
44
|
33
|
|
|
34
|
+class MyHomePage extends StatefulWidget {
|
|
35
|
+ MyHomePage({Key key, this.title}) : super(key: key);
|
45
|
36
|
|
|
37
|
+ final String title;
|
46
|
38
|
|
47
|
|
-class MyHomePage extends StatefulWidget {
|
48
|
39
|
@override
|
49
|
40
|
_MyHomePageState createState() => _MyHomePageState();
|
50
|
41
|
}
|
51
|
42
|
|
52
|
|
-class _MyHomePageState extends State<MyHomePage> {
|
53
|
|
- CalendarController _controller;
|
54
|
|
- Map<DateTime, List<dynamic>> _events;
|
55
|
|
- List<dynamic> _selectedEvents;
|
|
43
|
+//Definimos los controladores del Calendario
|
|
44
|
+class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
|
|
45
|
+ Map<DateTime, List> _events;
|
|
46
|
+ List _selectedEvents;
|
|
47
|
+ AnimationController _animationController;
|
|
48
|
+ CalendarController _calendarController;
|
|
49
|
+ Map<DateTime,List<dynamic>> _events2;
|
56
|
50
|
|
|
51
|
+//Definimos el dia elegido
|
57
|
52
|
@override
|
58
|
53
|
void initState() {
|
59
|
54
|
super.initState();
|
60
|
|
- _controller = CalendarController();
|
61
|
|
- _events = {};
|
62
|
|
- _selectedEvents = [];
|
|
55
|
+ final _selectedDay = DateTime.now();
|
|
56
|
+
|
|
57
|
+ _events = {
|
|
58
|
+ //Ejemplos de Citas Previamente Hechas de Prueba Para los Recordatorios
|
|
59
|
+ _selectedDay.add(Duration(days: 3)): Set.from([ 'Cita Cardiologo', 'Cita Dentista']).toList(),
|
|
60
|
+ _selectedDay.add(Duration(days: 22)): ['Cita Cardiologo', 'Cita Dentista'],
|
|
61
|
+
|
|
62
|
+ };
|
|
63
|
+ //Dias de Citas Seleccionados como Recordatorio
|
|
64
|
+ _selectedEvents = _events[_selectedDay] ?? [];
|
|
65
|
+ _calendarController = CalendarController();
|
|
66
|
+ _events2 = {};
|
|
67
|
+
|
|
68
|
+ _animationController = AnimationController(
|
|
69
|
+ vsync: this,
|
|
70
|
+ duration: const Duration(milliseconds: 400),
|
|
71
|
+ );
|
|
72
|
+
|
|
73
|
+ _animationController.forward();
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ Map<String,dynamic> encodeMap(Map<DateTime,dynamic> map) {
|
|
77
|
+ Map<String,dynamic> newMap = {};
|
|
78
|
+ map.forEach((key,value) {
|
|
79
|
+ newMap[key.toString()] = map[key];
|
|
80
|
+ });
|
|
81
|
+ return newMap;
|
63
|
82
|
}
|
64
|
83
|
|
65
|
|
- Map<DateTime, List<dynamic>> _groupEvents(List<EventModel> events) {
|
66
|
|
- Map<DateTime,List<dynamic>> data = {};
|
67
|
|
- events.forEach((event) {
|
68
|
|
- DateTime date = DateTime(event.eventDate.year, event.eventDate.month,
|
69
|
|
- event.eventDate.day, 12);
|
70
|
|
- if(data[date] == null) data[date] = [];
|
71
|
|
- data[date].add(event);
|
|
84
|
+ Map<DateTime,dynamic> decodeMap(Map<String,dynamic> map) {
|
|
85
|
+ Map<DateTime,dynamic> newMap = {};
|
|
86
|
+ map.forEach((key,value) {
|
|
87
|
+ newMap[DateTime.parse(key)] = map[key];
|
72
|
88
|
});
|
73
|
|
- return data;
|
|
89
|
+ return newMap;
|
74
|
90
|
}
|
75
|
91
|
|
76
|
92
|
|
77
|
93
|
|
78
|
94
|
@override
|
|
95
|
+ void dispose() {
|
|
96
|
+ _animationController.dispose();
|
|
97
|
+ _calendarController.dispose();
|
|
98
|
+ super.dispose();
|
|
99
|
+ }
|
|
100
|
+//Acciones definidas cuando se elige un dia en particular para ver si esta disponible o no
|
|
101
|
+ void _onDaySelected(DateTime day, List events, List holidays) {
|
|
102
|
+ print('CALLBACK: _onDaySelected');
|
|
103
|
+ setState(() {
|
|
104
|
+ _selectedEvents = events;
|
|
105
|
+ });
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ void _onVisibleDaysChanged(DateTime first, DateTime last, CalendarFormat format) {
|
|
109
|
+ print('CALLBACK: _onVisibleDaysChanged');
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ void _onCalendarCreated(DateTime first, DateTime last, CalendarFormat format) {
|
|
113
|
+ print('CALLBACK: _onCalendarCreated');
|
|
114
|
+ }
|
|
115
|
+//Definimos el "look" del area de las citas
|
|
116
|
+ @override
|
79
|
117
|
Widget build(BuildContext context) {
|
80
|
118
|
return Scaffold(
|
81
|
119
|
appBar: AppBar(
|
82
|
|
- title: Text('Citas Disponibles'),
|
|
120
|
+ title: Text(widget.title),
|
|
121
|
+ ),
|
|
122
|
+ body: Column(
|
|
123
|
+ mainAxisSize: MainAxisSize.max,
|
|
124
|
+ children: <Widget>[
|
|
125
|
+
|
|
126
|
+ _buildTableCalendar(
|
|
127
|
+
|
|
128
|
+ ),
|
|
129
|
+ // _buildTableCalendarWithBuilders(),
|
|
130
|
+ const SizedBox(height: 8.0),
|
|
131
|
+ _buildButtons(),
|
|
132
|
+ const SizedBox(height: 8.0),
|
|
133
|
+ Expanded(child: _buildEventList()),
|
|
134
|
+ ],
|
|
135
|
+ ),
|
|
136
|
+ );
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ // Simple configuracion de la Tabla de Calendario usando estilos
|
|
140
|
+ Widget _buildTableCalendar() {
|
|
141
|
+ return TableCalendar(
|
|
142
|
+ calendarController: _calendarController,
|
|
143
|
+ events: _events,
|
|
144
|
+ holidays: _holidays,
|
|
145
|
+ startingDayOfWeek: StartingDayOfWeek.monday,
|
|
146
|
+ calendarStyle: CalendarStyle(
|
|
147
|
+ selectedColor: Colors.lightBlueAccent,
|
|
148
|
+ todayColor: Colors.blueAccent,
|
|
149
|
+ markersColor: Colors.brown,
|
|
150
|
+ outsideDaysVisible: false,
|
83
|
151
|
),
|
84
|
|
- body: StreamBuilder<List<EventModel>>(
|
85
|
|
- // stream: eventDBS.streamList(),
|
86
|
|
- builder: (context, snapshot) {
|
87
|
|
- if (snapshot.hasData) {
|
88
|
|
- List<EventModel> allEvents = snapshot.data;
|
89
|
|
- if (allEvents.isNotEmpty) {
|
90
|
|
- _events = _groupEvents(allEvents);
|
91
|
|
- }
|
92
|
|
- }
|
93
|
|
-
|
94
|
|
- return SingleChildScrollView(
|
95
|
|
- child: Column(
|
96
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
97
|
|
- children: <Widget>[
|
98
|
|
- TableCalendar(
|
99
|
|
- events: _events,
|
100
|
|
- initialCalendarFormat: CalendarFormat.month,
|
101
|
|
- calendarStyle: CalendarStyle(
|
102
|
|
- canEventMarkersOverflow: true,
|
103
|
|
- todayColor: Colors.orange,
|
104
|
|
- selectedColor: Theme
|
105
|
|
- .of(context)
|
106
|
|
- .primaryColor,
|
107
|
|
- todayStyle: TextStyle(
|
108
|
|
- fontWeight: FontWeight.bold,
|
109
|
|
- fontSize: 18.0,
|
110
|
|
- color: Colors.white)),
|
111
|
|
- headerStyle: HeaderStyle(
|
112
|
|
- centerHeaderTitle: true,
|
113
|
|
- formatButtonDecoration: BoxDecoration(
|
114
|
|
- color: Colors.orange,
|
115
|
|
- borderRadius: BorderRadius.circular(20.0),
|
116
|
|
- ),
|
117
|
|
- formatButtonTextStyle: TextStyle(color: Colors.white),
|
118
|
|
- formatButtonShowsNext: false,
|
119
|
|
- ),
|
120
|
|
- startingDayOfWeek: StartingDayOfWeek.monday,
|
121
|
|
-
|
122
|
|
- builders: CalendarBuilders(
|
123
|
|
- selectedDayBuilder: (context, date, events) =>
|
124
|
|
- Container(
|
125
|
|
- margin: const EdgeInsets.all(4.0),
|
126
|
|
- alignment: Alignment.center,
|
127
|
|
- decoration: BoxDecoration(
|
128
|
|
- color: Theme
|
129
|
|
- .of(context)
|
130
|
|
- .primaryColor,
|
131
|
|
- borderRadius: BorderRadius.circular(10.0)),
|
132
|
|
- child: Text(
|
133
|
|
- date.day.toString(),
|
134
|
|
- style: TextStyle(color: Colors.white),
|
135
|
|
- )),
|
136
|
|
- todayDayBuilder: (context, date, events) =>
|
137
|
|
- Container(
|
138
|
|
- margin: const EdgeInsets.all(4.0),
|
139
|
|
- alignment: Alignment.center,
|
140
|
|
- decoration: BoxDecoration(
|
141
|
|
- color: Colors.orange,
|
142
|
|
- borderRadius: BorderRadius.circular(10.0)),
|
143
|
|
- child: Text(
|
144
|
|
- date.day.toString(),
|
145
|
|
- style: TextStyle(color: Colors.white),
|
146
|
|
- )),
|
147
|
|
- ),
|
148
|
|
- calendarController: _controller,
|
149
|
|
- ),
|
150
|
|
- ..._selectedEvents.map((event) =>
|
151
|
|
- ListTile(
|
152
|
|
- title: Text(event.title),
|
153
|
|
- onTap: () {
|
154
|
|
- Navigator.push(
|
155
|
|
- context,
|
156
|
|
- MaterialPageRoute(
|
157
|
|
- builder: (_) =>
|
158
|
|
- EventDetailsPage(
|
159
|
|
- event: event,
|
160
|
|
- )));
|
161
|
|
- },
|
162
|
|
- )),
|
163
|
|
- ],
|
|
152
|
+ headerStyle: HeaderStyle(
|
|
153
|
+ formatButtonTextStyle: TextStyle().copyWith(color: Colors.white, fontSize: 15.0),
|
|
154
|
+ formatButtonDecoration: BoxDecoration(
|
|
155
|
+ color: Colors.lightBlue,
|
|
156
|
+ borderRadius: BorderRadius.circular(16.0),
|
|
157
|
+ ),
|
|
158
|
+ ),
|
|
159
|
+ onDaySelected: _onDaySelected,
|
|
160
|
+ onVisibleDaysChanged: _onVisibleDaysChanged,
|
|
161
|
+ onCalendarCreated: _onCalendarCreated,
|
|
162
|
+ );
|
|
163
|
+ }
|
|
164
|
+ // Configuraciones detalladas del area de citas como definir dias, meses, etc.
|
|
165
|
+ Widget buildTableCalendarWithBuilders() {
|
|
166
|
+ return TableCalendar(
|
|
167
|
+ locale: 'pl_PL',
|
|
168
|
+ calendarController: _calendarController,
|
|
169
|
+ events: _events,
|
|
170
|
+ holidays: _holidays,
|
|
171
|
+ initialCalendarFormat: CalendarFormat.month,
|
|
172
|
+ formatAnimation: FormatAnimation.slide,
|
|
173
|
+ startingDayOfWeek: StartingDayOfWeek.sunday,
|
|
174
|
+ availableGestures: AvailableGestures.all,
|
|
175
|
+ availableCalendarFormats: const {
|
|
176
|
+ CalendarFormat.month: '',
|
|
177
|
+ CalendarFormat.week: '',
|
|
178
|
+ },
|
|
179
|
+ //Colores de los dias seleccionados
|
|
180
|
+ calendarStyle: CalendarStyle(
|
|
181
|
+ outsideDaysVisible: false,
|
|
182
|
+ weekendStyle: TextStyle().copyWith(color: Colors.blue),
|
|
183
|
+ holidayStyle: TextStyle().copyWith(color: Colors.blue),
|
|
184
|
+ ),
|
|
185
|
+ daysOfWeekStyle: DaysOfWeekStyle(
|
|
186
|
+ weekendStyle: TextStyle().copyWith(color: Colors.blue),
|
|
187
|
+ ),
|
|
188
|
+ headerStyle: HeaderStyle(
|
|
189
|
+ centerHeaderTitle: true,
|
|
190
|
+ formatButtonVisible: false,
|
|
191
|
+ ),
|
|
192
|
+ builders: CalendarBuilders(
|
|
193
|
+ selectedDayBuilder: (context, date, _) {
|
|
194
|
+ //Animacion del Calendario al cambiar el mes
|
|
195
|
+ return FadeTransition(
|
|
196
|
+ opacity: Tween(begin: 0.0, end: 1.0).animate(_animationController),
|
|
197
|
+ child: Container(
|
|
198
|
+ margin: const EdgeInsets.all(4.0),
|
|
199
|
+ padding: const EdgeInsets.only(top: 5.0, left: 6.0),
|
|
200
|
+ color: Colors.green,
|
|
201
|
+ width: 100,
|
|
202
|
+ height: 100,
|
|
203
|
+ child: Text(
|
|
204
|
+ '${date.day}',
|
|
205
|
+ style: TextStyle().copyWith(fontSize: 16.0),
|
|
206
|
+ ),
|
|
207
|
+ ),
|
|
208
|
+ );
|
|
209
|
+ },
|
|
210
|
+ todayDayBuilder: (context, date, _) {
|
|
211
|
+ return Container(
|
|
212
|
+ margin: const EdgeInsets.all(4.0),
|
|
213
|
+ padding: const EdgeInsets.only(top: 5.0, left: 6.0),
|
|
214
|
+ color: Colors.amber,
|
|
215
|
+ width: 100,
|
|
216
|
+ height: 100,
|
|
217
|
+ child: Text(
|
|
218
|
+ '${date.day}',
|
|
219
|
+ style: TextStyle().copyWith(fontSize: 16.0),
|
|
220
|
+ ),
|
|
221
|
+ );
|
|
222
|
+ },
|
|
223
|
+ markersBuilder: (context, date, events, holidays) {
|
|
224
|
+ final children = <Widget>[];
|
|
225
|
+
|
|
226
|
+ if (events.isNotEmpty) {
|
|
227
|
+ children.add(
|
|
228
|
+ Positioned(
|
|
229
|
+ right: 1,
|
|
230
|
+ bottom: 1,
|
|
231
|
+ child: _buildEventsMarker(date, events),
|
164
|
232
|
),
|
165
|
233
|
);
|
166
|
234
|
}
|
|
235
|
+
|
|
236
|
+ if (holidays.isNotEmpty) {
|
|
237
|
+ children.add(
|
|
238
|
+ Positioned(
|
|
239
|
+ right: -2,
|
|
240
|
+ top: -2,
|
|
241
|
+ child: _buildHolidaysMarker(),
|
|
242
|
+ ),
|
|
243
|
+ );
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ return children;
|
|
247
|
+ },
|
167
|
248
|
),
|
168
|
|
- floatingActionButton: FloatingActionButton(
|
169
|
|
- child: Icon(Icons.add),
|
170
|
|
- onPressed: () => Navigator.pushNamed(context, 'add_event'),
|
|
249
|
+ onDaySelected: (date, events, holidays) {
|
|
250
|
+ _onDaySelected(date, events, holidays);
|
|
251
|
+ _animationController.forward(from: 0.0);
|
|
252
|
+ },
|
|
253
|
+ onVisibleDaysChanged: _onVisibleDaysChanged,
|
|
254
|
+ onCalendarCreated: _onCalendarCreated,
|
|
255
|
+ );
|
|
256
|
+ }
|
|
257
|
+//Marcador de eventos (aparece debajo de los dias)
|
|
258
|
+ Widget _buildEventsMarker(DateTime date, List events) {
|
|
259
|
+ return AnimatedContainer(
|
|
260
|
+ duration: const Duration(milliseconds: 300),
|
|
261
|
+ decoration: BoxDecoration(
|
|
262
|
+ shape: BoxShape.rectangle,
|
|
263
|
+ color: _calendarController.isSelected(date)
|
|
264
|
+ ? Colors.brown[500]
|
|
265
|
+ : _calendarController.isToday(date) ? Colors.brown : Colors.blue,
|
|
266
|
+ ),
|
|
267
|
+ width: 16.0,
|
|
268
|
+ height: 16.0,
|
|
269
|
+ child: Center(
|
|
270
|
+ child: Text(
|
|
271
|
+ '${events.length}',
|
|
272
|
+ style: TextStyle().copyWith(
|
|
273
|
+ color: Colors.green,
|
|
274
|
+ fontSize: 12.0,
|
|
275
|
+ ),
|
|
276
|
+ ),
|
171
|
277
|
),
|
172
|
278
|
);
|
173
|
279
|
}
|
174
|
|
-}
|
175
|
280
|
|
|
281
|
+ Widget _buildHolidaysMarker() {
|
|
282
|
+ return Icon(
|
|
283
|
+ Icons.add_box,
|
|
284
|
+ size: 20.0,
|
|
285
|
+ color: Colors.blueGrey,
|
|
286
|
+ );
|
|
287
|
+ }
|
|
288
|
+
|
|
289
|
+ Widget _buildButtons() {
|
|
290
|
+ final dateTime = _events.keys.elementAt(_events.length - 2);
|
|
291
|
+ //Definimos formato del calendario (mes, 2 semanas, semana)
|
|
292
|
+ return Column(
|
|
293
|
+ children: <Widget>[
|
|
294
|
+ Row(
|
|
295
|
+ mainAxisSize: MainAxisSize.max,
|
|
296
|
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
297
|
+ children: <Widget>[
|
|
298
|
+ RaisedButton(
|
|
299
|
+ child: Text('Mes'),
|
|
300
|
+ onPressed: () {
|
|
301
|
+ setState(() {
|
|
302
|
+ _calendarController.setCalendarFormat(CalendarFormat.month);
|
|
303
|
+ });
|
|
304
|
+ },
|
|
305
|
+ ),
|
|
306
|
+ RaisedButton(
|
|
307
|
+ child: Text('2 Semanas'),
|
|
308
|
+ onPressed: () {
|
|
309
|
+ setState(() {
|
|
310
|
+ _calendarController.setCalendarFormat(CalendarFormat.twoWeeks);
|
|
311
|
+ });
|
|
312
|
+ },
|
|
313
|
+ ),
|
|
314
|
+ RaisedButton(
|
|
315
|
+ child: Text('Semana'),
|
|
316
|
+ onPressed: () {
|
|
317
|
+ setState(() {
|
|
318
|
+ _calendarController.setCalendarFormat(CalendarFormat.week);
|
|
319
|
+ });
|
|
320
|
+ },
|
|
321
|
+ ),
|
|
322
|
+ ],
|
|
323
|
+ ),
|
|
324
|
+ const SizedBox(height: 8.0),
|
|
325
|
+ RaisedButton(
|
|
326
|
+ child: Text('Recuerde Cita ${dateTime.day}-${dateTime.month}-${dateTime.year}'),
|
|
327
|
+ onPressed: () {
|
|
328
|
+ _calendarController.setSelectedDay(
|
|
329
|
+ DateTime(dateTime.year, dateTime.month, dateTime.day),
|
|
330
|
+ runCallback: true,
|
|
331
|
+ );
|
|
332
|
+ },
|
|
333
|
+ ),
|
|
334
|
+ ],
|
|
335
|
+ );
|
|
336
|
+ }
|
|
337
|
+
|
|
338
|
+ //Muestra las citas ya creadas
|
|
339
|
+ Widget _buildEventList() {
|
|
340
|
+ return ListView(
|
|
341
|
+ children: _selectedEvents
|
|
342
|
+ .map((event) => Container(
|
|
343
|
+ decoration: BoxDecoration(
|
|
344
|
+ border: Border.all(width: 0.8),
|
|
345
|
+ borderRadius: BorderRadius.circular(12.0),
|
|
346
|
+ ),
|
|
347
|
+ margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
|
348
|
+ child: ListTile(
|
|
349
|
+ title: Text(event.toString()),
|
|
350
|
+ onTap: () => print('$event tapped!'),
|
|
351
|
+ ),
|
|
352
|
+ ))
|
|
353
|
+ .toList(),
|
|
354
|
+ );
|
|
355
|
+ }
|
|
356
|
+}
|