|
@@ -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
|
+);
|