Browse Source

Primer Sprint

JorgeIan 3 years ago
parent
commit
d6b0adc272

+ 21
- 4
fast_med_flutter/lib/routes/calendario.dart View File

@@ -2,16 +2,30 @@ import 'package:flutter/material.dart';
2 2
 import 'package:fast_med_flutter/ui/pages/add_event.dart';
3 3
 import 'package:fast_med_flutter/ui/pages/view_event.dart';
4 4
 import 'package:table_calendar/table_calendar.dart';
5
-import 'package:firebase_core/firebase_core.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;
6 10
 
7 11
 import 'model/event.dart';
8 12
 
9 13
 void main() async{
14
+
15
+  var url = 'https://ada.uprrp.edu/~jorge.lopez19/FastMed/API/InsertEvent.php';
10 16
   WidgetsFlutterBinding.ensureInitialized();
11
-  await Firebase.initializeApp();
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
+  //);
12 24
   runApp(Calendario());
13 25
 }
14 26
 
27
+
28
+
15 29
 class Calendario extends StatelessWidget {
16 30
   @override
17 31
   Widget build(BuildContext context) {
@@ -59,6 +73,8 @@ class _MyHomePageState extends State<MyHomePage> {
59 73
     return data;
60 74
   }
61 75
 
76
+
77
+
62 78
   @override
63 79
   Widget build(BuildContext context) {
64 80
     return Scaffold(
@@ -81,7 +97,7 @@ class _MyHomePageState extends State<MyHomePage> {
81 97
                 children: <Widget>[
82 98
                   TableCalendar(
83 99
                     events: _events,
84
-                    initialCalendarFormat: CalendarFormat.week,
100
+                    initialCalendarFormat: CalendarFormat.month,
85 101
                     calendarStyle: CalendarStyle(
86 102
                         canEventMarkersOverflow: true,
87 103
                         todayColor: Colors.orange,
@@ -155,4 +171,5 @@ class _MyHomePageState extends State<MyHomePage> {
155 171
       ),
156 172
     );
157 173
   }
158
-}
174
+}
175
+

+ 108
- 41
fast_med_flutter/lib/ui/pages/add_event.dart View File

@@ -1,6 +1,9 @@
1 1
 import 'package:fast_med_flutter/model/event.dart';
2 2
 import 'package:flutter/material.dart';
3 3
 import 'package:fast_med_flutter/res/event_firestore_service.dart';
4
+import 'package:http/http.dart' as http;
5
+import 'dart:async';
6
+import 'dart:convert';
4 7
 
5 8
 class AddEventPage extends StatefulWidget {
6 9
   final EventModel note;
@@ -15,7 +18,16 @@ class _AddEventPageState extends State<AddEventPage> {
15 18
   TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
16 19
   TextEditingController _title;
17 20
   TextEditingController _description;
21
+  TextEditingController _number;
22
+  TextEditingController _name;
23
+  TextEditingController _reason;
24
+  TextEditingController _date;
25
+  TextEditingController _time;
26
+
18 27
   DateTime _eventDate;
28
+  DateTime _eventTime;
29
+  DateTime selectedDate = DateTime.now();
30
+  List data;
19 31
   final _formKey = GlobalKey<FormState>();
20 32
   final _key = GlobalKey<ScaffoldState>();
21 33
   bool processing;
@@ -25,10 +37,16 @@ class _AddEventPageState extends State<AddEventPage> {
25 37
     super.initState();
26 38
     _title = TextEditingController(text: widget.note != null ? widget.note.title : "");
27 39
     _description = TextEditingController(text:  widget.note != null ? widget.note.description : "");
40
+    //_name = TextEditingController(text:  widget.note != null ? widget.note.name : "");
41
+    //_number = TextEditingController(text:  widget.note != null ? widget.note.number : "");
42
+   // _reason = TextEditingController(text:  widget.note != null ? widget.note.reason : "");
43
+    //_date = TextEditingController(text:  widget.note != null ?  widget.note.eventDate;
28 44
     _eventDate = DateTime.now();
45
+    //_eventTime = Time.now();
29 46
     processing = false;
30 47
   }
31 48
 
49
+
32 50
   @override
33 51
   Widget build(BuildContext context) {
34 52
     return Scaffold(
@@ -45,7 +63,7 @@ class _AddEventPageState extends State<AddEventPage> {
45 63
               Padding(
46 64
                 padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
47 65
                 child: TextFormField(
48
-                  controller: _title,
66
+                  controller: _name,
49 67
                   validator: (value) =>
50 68
                       (value.isEmpty) ? "Favor Anotar Nombre del Paciente" : null,
51 69
                   style: style,
@@ -59,7 +77,19 @@ class _AddEventPageState extends State<AddEventPage> {
59 77
               Padding(
60 78
                 padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
61 79
                 child: TextFormField(
62
-                  controller: _description,
80
+                  controller: _number,
81
+                  validator: (value) =>
82
+                  (value.isEmpty) ? "Favor Anotar Numero de Telefono" : null,
83
+                  style: style,
84
+                  decoration: InputDecoration(
85
+                      labelText: "Numero de Telefono",
86
+                      border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
87
+                ),
88
+              ),
89
+              Padding(
90
+                padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
91
+                child: TextFormField(
92
+                  controller: _reason,
63 93
                   minLines: 3,
64 94
                   maxLines: 5,
65 95
                   validator: (value) =>
@@ -84,49 +114,69 @@ class _AddEventPageState extends State<AddEventPage> {
84 114
                 },
85 115
               ),
86 116
 
117
+              ListTile(
118
+                title: Text("Time (HH: mm)"),
119
+                subtitle: Text("${_eventDate.hour} - ${_eventDate.minute} - ${_eventDate.second}"),
120
+                onTap: ()async{
121
+                 final selectedTime = await _selectTime(context);
122
+                 if (selectedTime == null) return;
123
+                  print(selectedTime);
124
+
125
+                setState(() {
126
+                this.selectedDate = DateTime(
127
+                selectedTime.hour,
128
+                selectedTime.minute,
129
+                );
130
+                    });
131
+                  }
132
+                  ),
87 133
               SizedBox(height: 10.0),
88 134
               processing
89 135
                   ? Center(child: CircularProgressIndicator())
90 136
                   : Padding(
91
-                      padding: const EdgeInsets.symmetric(horizontal: 16.0),
92
-                      child: Material(
93
-                        elevation: 5.0,
94
-                        borderRadius: BorderRadius.circular(30.0),
95
-                        color: Theme.of(context).primaryColor,
96
-                        child: MaterialButton(
97
-                          onPressed: () async {
98
-                            if (_formKey.currentState.validate()) {
99
-                              setState(() {
100
-                                processing = true;
101
-                              });
102
-                              if(widget.note != null) {
103
-                                await eventDBS.updateData(widget.note.id,{
104
-                                  "title": _title.text,
105
-                                  "description": _description.text,
106
-                                  "event_date": widget.note.eventDate
107
-                                });
108
-                              }else{
109
-                                await eventDBS.createItem(EventModel(
110
-                                  title: _title.text,
111
-                                  description: _description.text,
112
-                                  eventDate: _eventDate
113
-                                ));
114
-                              }
115
-                              Navigator.pop(context);
116
-                              setState(() {
117
-                                processing = false;
118
-                              });
119
-                            }
120
-                          },
121
-                          child: Text(
122
-                            "Crear Su Cita Ahora",
123
-                            style: style.copyWith(
124
-                                color: Colors.white,
125
-                                fontWeight: FontWeight.bold),
126
-                          ),
127
-                        ),
128
-                      ),
137
+                padding: const EdgeInsets.symmetric(horizontal: 16.0),
138
+                child: Material(
139
+                  elevation: 5.0,
140
+                  borderRadius: BorderRadius.circular(30.0),
141
+                  color: Theme.of(context).primaryColor,
142
+                  child: MaterialButton(
143
+                    onPressed: () async {
144
+                      if (_formKey.currentState.validate()) {
145
+                        setState(() {
146
+                          processing = true;
147
+                        });
148
+                        if(widget.note != null) {
149
+                          await eventDBS.updateData(widget.note.id,{
150
+
151
+
152
+                          "title": _title.text,
153
+                          "number": _number.text,
154
+                          "reason": _reason.text,
155
+                          "event_date": widget.note.eventDate,
156
+                          //"time": widget.note.DateTime,
157
+                          });
158
+                        }else{
159
+                          await eventDBS.createItem(EventModel(
160
+                              title: _title.text,
161
+                              description: _description.text,
162
+                              eventDate: _eventDate
163
+                          ));
164
+                        }
165
+                        Navigator.pop(context);
166
+                        setState(() {
167
+                          processing = false;
168
+                        });
169
+                      }
170
+                    },
171
+                    child: Text(
172
+                      "Crear Su Cita Ahora",
173
+                      style: style.copyWith(
174
+                          color: Colors.white,
175
+                          fontWeight: FontWeight.bold),
129 176
                     ),
177
+                  ),
178
+                ),
179
+              ),
130 180
             ],
131 181
           ),
132 182
         ),
@@ -134,10 +184,27 @@ class _AddEventPageState extends State<AddEventPage> {
134 184
     );
135 185
   }
136 186
 
187
+
137 188
   @override
138 189
   void dispose() {
139 190
     _title.dispose();
140 191
     _description.dispose();
141 192
     super.dispose();
142 193
   }
143
-}
194
+}
195
+
196
+Future<TimeOfDay> _selectTime(BuildContext context) {
197
+  final now = DateTime.now();
198
+
199
+  return showTimePicker(
200
+    context: context,
201
+    initialTime: TimeOfDay(hour: now.hour, minute: now.minute),
202
+  );
203
+}
204
+
205
+Future<DateTime> _selectDateTime(BuildContext context) => showDatePicker(
206
+  context: context,
207
+  initialDate: DateTime.now().add(Duration(seconds: 1)),
208
+  firstDate: DateTime.now(),
209
+  lastDate: DateTime(2100),
210
+);

+ 62
- 0
fast_med_flutter/lib/widgets/date_time_picker_widget.dart View File

@@ -0,0 +1,62 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:intl/intl.dart';
3
+
4
+class DateTimePickerWidget extends StatefulWidget {
5
+  @override
6
+  _DateTimePickerWidgetState createState() => _DateTimePickerWidgetState();
7
+}
8
+
9
+class _DateTimePickerWidgetState extends State<DateTimePickerWidget> {
10
+  DateTime selectedDate = DateTime.now();
11
+
12
+  final DateFormat dateFormat = DateFormat('yyyy-MM-dd HH:mm');
13
+
14
+  @override
15
+  Widget build(BuildContext context) {
16
+    return Column(
17
+      mainAxisAlignment: MainAxisAlignment.center,
18
+      children: <Widget>[
19
+        Text(dateFormat.format(selectedDate)),
20
+        RaisedButton(
21
+          child: Text('Choose new date time'),
22
+          onPressed: () async {
23
+            final selectedDate = await _selectDateTime(context);
24
+            if (selectedDate == null) return;
25
+
26
+            print(selectedDate);
27
+
28
+            final selectedTime = await _selectTime(context);
29
+            if (selectedTime == null) return;
30
+            print(selectedTime);
31
+
32
+            setState(() {
33
+              this.selectedDate = DateTime(
34
+                selectedDate.year,
35
+                selectedDate.month,
36
+                selectedDate.day,
37
+                selectedTime.hour,
38
+                selectedTime.minute,
39
+              );
40
+            });
41
+          },
42
+        ),
43
+      ],
44
+    );
45
+  }
46
+
47
+  Future<TimeOfDay> _selectTime(BuildContext context) {
48
+    final now = DateTime.now();
49
+
50
+    return showTimePicker(
51
+      context: context,
52
+      initialTime: TimeOfDay(hour: now.hour, minute: now.minute),
53
+    );
54
+  }
55
+
56
+  Future<DateTime> _selectDateTime(BuildContext context) => showDatePicker(
57
+        context: context,
58
+        initialDate: DateTime.now().add(Duration(seconds: 1)),
59
+        firstDate: DateTime.now(),
60
+        lastDate: DateTime(2100),
61
+      );
62
+}

+ 35
- 0
fast_med_flutter/lib/widgets/date_time_picker_widget2.dart View File

@@ -0,0 +1,35 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:intl/intl.dart';
3
+import 'package:fast_med_flutter/widgets/notifcation_dialog.dart';
4
+
5
+class DateTimePickerWidget2 extends StatefulWidget {
6
+  @override
7
+  _DateTimePickerWidget2State createState() => _DateTimePickerWidget2State();
8
+}
9
+
10
+class _DateTimePickerWidget2State extends State<DateTimePickerWidget2> {
11
+  DateTime selectedDate = DateTime.now();
12
+
13
+  final DateFormat dateFormat = DateFormat('yyyy-MM-dd HH:mm');
14
+
15
+  @override
16
+  Widget build(BuildContext context) {
17
+    return Column(
18
+      mainAxisAlignment: MainAxisAlignment.center,
19
+      children: <Widget>[
20
+        Text(dateFormat.format(selectedDate)),
21
+        RaisedButton(
22
+          child: Text('Choose new date time'),
23
+          onPressed: () async {
24
+            showDateTimeDialog(context, initialDate: selectedDate,
25
+                onSelectedDate: (selectedDate) {
26
+              setState(() {
27
+                this.selectedDate = selectedDate;
28
+              });
29
+            });
30
+          },
31
+        ),
32
+      ],
33
+    );
34
+  }
35
+}

+ 132
- 0
fast_med_flutter/lib/widgets/notifcation_dialog.dart View File

@@ -0,0 +1,132 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:intl/intl.dart';
3
+
4
+Future<TimeOfDay> _selectTime(BuildContext context,
5
+    {@required DateTime initialDate}) {
6
+  final now = DateTime.now();
7
+
8
+  return showTimePicker(
9
+    context: context,
10
+    initialTime: TimeOfDay(hour: initialDate.hour, minute: initialDate.minute),
11
+  );
12
+}
13
+
14
+Future<DateTime> _selectDateTime(BuildContext context,
15
+    {@required DateTime initialDate}) {
16
+  final now = DateTime.now();
17
+  final newestDate = initialDate.isAfter(now) ? initialDate : now;
18
+
19
+  return showDatePicker(
20
+    context: context,
21
+    initialDate: newestDate.add(Duration(seconds: 1)),
22
+    firstDate: now,
23
+    lastDate: DateTime(2100),
24
+  );
25
+}
26
+
27
+Dialog showDateTimeDialog(
28
+  BuildContext context, {
29
+  @required ValueChanged<DateTime> onSelectedDate,
30
+  @required DateTime initialDate,
31
+}) {
32
+  final dialog = Dialog(
33
+    child: DateTimeDialog(
34
+        onSelectedDate: onSelectedDate, initialDate: initialDate),
35
+  );
36
+
37
+  showDialog(context: context, builder: (BuildContext context) => dialog);
38
+}
39
+
40
+class DateTimeDialog extends StatefulWidget {
41
+  final ValueChanged<DateTime> onSelectedDate;
42
+  final DateTime initialDate;
43
+
44
+  const DateTimeDialog({
45
+    @required this.onSelectedDate,
46
+    @required this.initialDate,
47
+    Key key,
48
+  }) : super(key: key);
49
+  @override
50
+  _DateTimeDialogState createState() => _DateTimeDialogState();
51
+}
52
+
53
+class _DateTimeDialogState extends State<DateTimeDialog> {
54
+  DateTime selectedDate;
55
+
56
+  @override
57
+  void initState() {
58
+    super.initState();
59
+
60
+    selectedDate = widget.initialDate;
61
+  }
62
+
63
+  @override
64
+  Widget build(BuildContext context) => Padding(
65
+        padding: const EdgeInsets.all(16),
66
+        child: Column(
67
+          mainAxisAlignment: MainAxisAlignment.center,
68
+          mainAxisSize: MainAxisSize.min,
69
+          children: <Widget>[
70
+            Text(
71
+              'Select time',
72
+              style: Theme.of(context).textTheme.title,
73
+            ),
74
+            const SizedBox(height: 16),
75
+            Row(
76
+              mainAxisAlignment: MainAxisAlignment.center,
77
+              children: <Widget>[
78
+                RaisedButton(
79
+                  child: Text(DateFormat('yyyy-MM-dd').format(selectedDate)),
80
+                  onPressed: () async {
81
+                    final date = await _selectDateTime(context,
82
+                        initialDate: selectedDate);
83
+                    if (date == null) return;
84
+
85
+                    setState(() {
86
+                      selectedDate = DateTime(
87
+                        date.year,
88
+                        date.month,
89
+                        date.day,
90
+                        selectedDate.hour,
91
+                        selectedDate.minute,
92
+                      );
93
+                    });
94
+
95
+                    widget.onSelectedDate(selectedDate);
96
+                  },
97
+                ),
98
+                const SizedBox(width: 8),
99
+                RaisedButton(
100
+                  child: Text(DateFormat('HH:mm').format(selectedDate)),
101
+                  onPressed: () async {
102
+                    final time =
103
+                        await _selectTime(context, initialDate: selectedDate);
104
+                    if (time == null) return;
105
+
106
+                    setState(() {
107
+                      selectedDate = DateTime(
108
+                        selectedDate.year,
109
+                        selectedDate.month,
110
+                        selectedDate.day,
111
+                        time.hour,
112
+                        time.minute,
113
+                      );
114
+                    });
115
+
116
+                    widget.onSelectedDate(selectedDate);
117
+                  },
118
+                ),
119
+              ],
120
+            ),
121
+            const SizedBox(height: 16),
122
+            OutlineButton(
123
+              child: Text('Schedule!'),
124
+              onPressed: () {
125
+                Navigator.of(context).pop();
126
+              },
127
+              highlightColor: Colors.orange,
128
+            ),
129
+          ],
130
+        ),
131
+      );
132
+}