3 Commits

Autor SHA1 Nachricht Datum
  JorgeIan c99cc96a40 Merge branch 'master' of https://git.ccom.uprrp.edu/CCOM4030/Mobile_Health vor 3 Jahren
  JorgeIan fded3729d7 Calendario 3 vor 3 Jahren
  JorgeIan 3c2cdeb599 Update pubspec.lock vor 3 Jahren
1 geänderte Dateien mit 229 neuen und 0 gelöschten Zeilen
  1. 229
    0
      fast_med_flutter/lib/routes/calendario.dart

+ 229
- 0
fast_med_flutter/lib/routes/calendario.dart Datei anzeigen

@@ -0,0 +1,229 @@
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';
4
+import 'package:table_calendar/table_calendar.dart';
5
+import 'package:http/http.dart' as http;
6
+
7
+import 'package:fast_med_flutter/model/event.dart';
8
+
9
+// Dias de Citas No Disponibles
10
+
11
+final Map<DateTime, List> _holidays = {
12
+  DateTime(2020, 11, 6): ['No Hay Citas'],
13
+  DateTime(2020, 11, 3): ['Dia Elecciones'],
14
+  DateTime(2020, 12, 25): ['Christmas'],
15
+  DateTime(2020, 12, 31): ['Despedida del anyo nuevo'],
16
+  DateTime(2021, 01, 01): ['Anyo Nuevo'],
17
+};
18
+
19
+//Iniciar la Seccion de las Citas
20
+
21
+void main() async{
22
+
23
+  //Comunicacion con el servidor antes de iniciar el app
24
+
25
+  var url = 'https://ada.uprrp.edu/~jorge.lopez19/FastMed/API/InsertEvent.php';
26
+  WidgetsFlutterBinding.ensureInitialized();
27
+  final data = await http.post(url, body: {
28
+  });
29
+  runApp(Calendario());
30
+
31
+}
32
+
33
+//Inicio del Area de las Citas Disponibles
34
+
35
+class Calendario extends StatelessWidget {
36
+  @override
37
+  Widget build(BuildContext context) {
38
+    return MaterialApp(
39
+      title: 'Citas Disponibles',
40
+      theme: ThemeData(
41
+        primarySwatch: Colors.blue,
42
+      ),
43
+      home: MyHomePage(),
44
+      routes: {
45
+        "add_event": (_) => AddEventPage(),
46
+      },
47
+    );
48
+  }
49
+}
50
+
51
+
52
+// Define el homepage para el area de citas
53
+
54
+class MyHomePage extends StatefulWidget {
55
+  @override
56
+  _MyHomePageState createState() => _MyHomePageState();
57
+}
58
+
59
+class _MyHomePageState extends State<MyHomePage> {
60
+  CalendarController _controller;
61
+  Map<DateTime, List<dynamic>> _events;
62
+  List<dynamic> _selectedEvents;
63
+
64
+  @override
65
+  void initState() {
66
+    super.initState();
67
+    final _selectedDay = DateTime.now();
68
+    _controller = CalendarController();
69
+    _events = {
70
+      //Ejemplos de Citas Previamente Hechas de Prueba Para los Recordatorios
71
+      _selectedDay.add(Duration(days: 3)): Set.from(
72
+          [ 'Cita Cardiologo', 'Cita Dentista']).toList(),
73
+      _selectedDay.add(Duration(days: 22)): [
74
+        'Cita Cardiologo',
75
+        'Cita Dentista'
76
+      ],
77
+    };
78
+    _selectedEvents = _events[_selectedDay] ?? [];
79
+    void _onDaySelected(DateTime day, List events, List holidays) {
80
+      print('CALLBACK: _onDaySelected');
81
+      setState(() {
82
+        _selectedEvents = _events[_selectedDay] ?? [];
83
+      });
84
+    }
85
+  }
86
+
87
+  Map<String, dynamic> encodeMap(Map<DateTime, dynamic> map) {
88
+    Map<String, dynamic> newMap = {};
89
+    map.forEach((key, value) {
90
+      newMap[key.toString()] = map[key];
91
+    });
92
+    return newMap;
93
+  }
94
+
95
+  Map<DateTime, List<dynamic>> _groupEvents(List<EventModel> events) {
96
+    Map<DateTime, List<dynamic>> data = {};
97
+    events.forEach((event) {
98
+      DateTime date = DateTime(event.eventDate.year, event.eventDate.month,
99
+          event.eventDate.day, 12);
100
+      if (data[date] == null) data[date] = [];
101
+      data[date].add(event);
102
+    });
103
+    return data;
104
+  }
105
+
106
+
107
+  @override
108
+//Marca en el calendario los dias que no esta disponibles para hacer horarios
109
+  void _onDaySelected(DateTime day, List events, List holidays) {
110
+    print('CALLBACK: _onDaySelected');
111
+    setState(() {
112
+      _selectedEvents = events;
113
+    });
114
+  }
115
+
116
+  void _onVisibleDaysChanged(DateTime first, DateTime last,
117
+      CalendarFormat format) {
118
+    print('CALLBACK: _onVisibleDaysChanged');
119
+  }
120
+
121
+  void _onCalendarCreated(DateTime first, DateTime last,
122
+      CalendarFormat format) {
123
+    print('CALLBACK: _onCalendarCreated');
124
+  }
125
+
126
+//Definimos los detalles del area de las citas
127
+  @override
128
+  Widget build(BuildContext context) {
129
+    return Scaffold(
130
+      appBar: AppBar(
131
+        title: Text('Citas Disponibles'),
132
+      ),
133
+      body: StreamBuilder<List<EventModel>>(
134
+        // stream: eventDBS.streamList(),
135
+          builder: (context, snapshot) {
136
+            if (snapshot.hasData) {
137
+              List<EventModel> allEvents = snapshot.data;
138
+              if (allEvents.isNotEmpty) {
139
+                _events = _groupEvents(allEvents);
140
+              }
141
+            }
142
+
143
+            return SingleChildScrollView(
144
+              child: Column(
145
+                crossAxisAlignment: CrossAxisAlignment.start,
146
+                children: <Widget>[
147
+                  TableCalendar(
148
+                    events: _events,
149
+                    holidays: _holidays,
150
+                    initialCalendarFormat: CalendarFormat.month,
151
+                    calendarStyle: CalendarStyle(
152
+                        canEventMarkersOverflow: true,
153
+                        todayColor: Colors.orange,
154
+                        selectedColor: Theme
155
+                            .of(context)
156
+                            .primaryColor,
157
+                        todayStyle: TextStyle(
158
+                            fontWeight: FontWeight.bold,
159
+                            fontSize: 18.0,
160
+                            color: Colors.white)),
161
+                    headerStyle: HeaderStyle(
162
+                      centerHeaderTitle: true,
163
+                      formatButtonDecoration: BoxDecoration(
164
+                        color: Colors.orange,
165
+                        borderRadius: BorderRadius.circular(20.0),
166
+                      ),
167
+                      formatButtonTextStyle: TextStyle(color: Colors.white),
168
+                      formatButtonShowsNext: false,
169
+                    ),
170
+                    startingDayOfWeek: StartingDayOfWeek.monday,
171
+                    onVisibleDaysChanged: _onVisibleDaysChanged,
172
+                    onCalendarCreated: _onCalendarCreated,
173
+
174
+                    builders: CalendarBuilders(
175
+                      selectedDayBuilder: (context, date, events) =>
176
+                          Container(
177
+                              margin: const EdgeInsets.all(4.0),
178
+                              alignment: Alignment.center,
179
+                              decoration: BoxDecoration(
180
+                                  color: Theme
181
+                                      .of(context)
182
+                                      .primaryColor,
183
+                                  borderRadius: BorderRadius.circular(10.0)),
184
+                              child: Text(
185
+                                date.day.toString(),
186
+                                style: TextStyle(color: Colors.white),
187
+                              )),
188
+                      todayDayBuilder: (context, date, events) =>
189
+                          Container(
190
+                              margin: const EdgeInsets.all(4.0),
191
+                              alignment: Alignment.center,
192
+                              decoration: BoxDecoration(
193
+                                  color: Colors.orange,
194
+                                  borderRadius: BorderRadius.circular(10.0)),
195
+                              child: Text(
196
+                                date.day.toString(),
197
+                                style: TextStyle(color: Colors.white),
198
+                              )),
199
+                    ),
200
+                    calendarController: _controller,
201
+                  ),
202
+                  ..._selectedEvents.map((event) =>
203
+                      ListTile(
204
+                        title: Text(event.title),
205
+                        onTap: () {
206
+                          Navigator.push(
207
+                              context,
208
+                              MaterialPageRoute(
209
+                                  builder: (_) =>
210
+                                      EventDetailsPage(
211
+                                        event: event,
212
+                                      )));
213
+                        },
214
+                      )),
215
+                ],
216
+              ),
217
+            );
218
+          }
219
+      ),
220
+      floatingActionButton: FloatingActionButton(
221
+        child: Icon(Icons.add),
222
+        onPressed: () => Navigator.pushNamed(context, 'add_event'),
223
+      ),
224
+    );
225
+  }
226
+}
227
+
228
+
229
+