No Description

add_event.dart 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import 'package:fast_med_flutter/model/event.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:fast_med_flutter/res/event_firestore_service.dart';
  4. import 'package:http/http.dart' as http;
  5. import 'dart:async';
  6. class AddEventPage extends StatefulWidget {
  7. final EventModel note;
  8. const AddEventPage({Key key, this.note}) : super(key: key);
  9. @override
  10. _AddEventPageState createState() => _AddEventPageState();
  11. }
  12. //Controles de cada Evento que usaremos en todos los files
  13. class _AddEventPageState extends State<AddEventPage> {
  14. TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
  15. TextEditingController _title;
  16. TextEditingController _description;
  17. TextEditingController _number;
  18. TextEditingController _name;
  19. TextEditingController _reason;
  20. DateTime _eventDate;
  21. DateTime _eventTime;
  22. DateTime selectedDate = DateTime.now();
  23. List data;
  24. List holidays;
  25. final _formKey = GlobalKey<FormState>();
  26. final _key = GlobalKey<ScaffoldState>();
  27. bool processing;
  28. @override
  29. void initState() {
  30. super.initState();
  31. _title = TextEditingController(text: widget.note != null ? widget.note.title : "");
  32. _description = TextEditingController(text: widget.note != null ? widget.note.description : "");
  33. _name = TextEditingController(text: widget.note != null ? widget.note.name : "");
  34. _number = TextEditingController(text: widget.note != null ? widget.note.number : "");
  35. _reason = TextEditingController(text: widget.note != null ? widget.note.reason : "");
  36. _eventDate = DateTime.now();
  37. _eventTime = DateTime.now();
  38. processing = false;
  39. }
  40. // Definimos el Formulario con cada parametro para crear la cita
  41. @override
  42. Widget build(BuildContext context) {
  43. return Scaffold(
  44. appBar: AppBar(
  45. title: Text(widget.note != null ? "Edit Note" : "Crear Su Cita"),
  46. ),
  47. key: _key,
  48. body: Form(
  49. key: _formKey,
  50. child: Container(
  51. alignment: Alignment.center,
  52. child: ListView(
  53. children: <Widget>[
  54. // Area donde paciente anota su nombre. Si esta vacio no lo acepta.
  55. Padding(
  56. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  57. child: TextFormField(
  58. controller: _name,
  59. validator: (value) =>
  60. (value.isEmpty) ? "Favor Anotar Nombre del Paciente" : null,
  61. style: style,
  62. decoration: InputDecoration(
  63. labelText: "Nombre completo del paciente",
  64. filled: true,
  65. fillColor: Colors.white,
  66. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  67. ),
  68. ),
  69. //Area donde el paciente debe anotar su numero de telefono. Si esta vacio no lo acepta.
  70. Padding(
  71. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  72. child: TextFormField(
  73. controller: _number,
  74. validator: (value) =>
  75. (value.isEmpty) ? "Favor Anotar Numero de Telefono" : null,
  76. style: style,
  77. decoration: InputDecoration(
  78. labelText: "Numero de Telefono",
  79. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  80. ),
  81. ),
  82. //Area donde el paciente explica la razon de su cita medica. Si esta vacio no lo acepta
  83. Padding(
  84. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  85. child: TextFormField(
  86. controller: _reason,
  87. minLines: 3,
  88. maxLines: 5,
  89. validator: (value) =>
  90. (value.isEmpty) ? "Favor Explicar Razon Para La Cita" : null,
  91. style: style,
  92. decoration: InputDecoration(
  93. labelText: "Razones para su cita",
  94. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  95. ),
  96. ),
  97. const SizedBox(height: 10.0),
  98. //Area donde el paciente puede cambiar la fecha para la cita
  99. ListTile(
  100. title: Text("Date (YYYY-MM-DD)"),
  101. subtitle: Text("${_eventDate.year} - ${_eventDate.month} - ${_eventDate.day}"),
  102. onTap: ()async{
  103. DateTime picked = await showDatePicker(context: context, initialDate: _eventDate, firstDate: DateTime(_eventDate.year-5), lastDate: DateTime(_eventDate.year+5));
  104. if(picked != null) {
  105. setState(() {
  106. _eventDate = picked;
  107. });
  108. }
  109. },
  110. ),
  111. //Area donde el paciente puede elegir y cambiar la hora para la cita
  112. ListTile(
  113. title: Text("Time (HH: mm)"),
  114. subtitle: Text("${_eventDate.hour} - ${_eventDate.minute} - ${_eventDate.second}"),
  115. onTap: ()async{
  116. final selectedTime = await _selectTime(context);
  117. if (selectedTime == null) return;
  118. print(selectedTime);
  119. setState(() {
  120. this.selectedDate = DateTime(
  121. selectedTime.hour,
  122. selectedTime.minute,
  123. );
  124. });
  125. }
  126. ),
  127. SizedBox(height: 10.0),
  128. //Se define el envio de los parametros al usar el boton de Crear la Cita
  129. processing
  130. ? Center(child: CircularProgressIndicator())
  131. : Padding(
  132. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  133. child: Material(
  134. elevation: 5.0,
  135. borderRadius: BorderRadius.circular(30.0),
  136. color: Theme.of(context).primaryColor,
  137. child: MaterialButton(
  138. onPressed: () async {
  139. if (_formKey.currentState.validate()) {
  140. setState(() {
  141. processing = true;
  142. });
  143. if(widget.note != null) {
  144. await eventDBS.updateData(widget.note.id,{
  145. "title": _title.text,
  146. "number": _number.text,
  147. "reason": _reason.text,
  148. "event_date": widget.note.eventDate,
  149. "time": widget.note.eventTime,
  150. });
  151. }else{
  152. await eventDBS.createItem(EventModel(
  153. title: _title.text,
  154. description: _description.text,
  155. name: _name.text,
  156. number: _number.text,
  157. reason: _reason.text,
  158. eventDate: _eventDate
  159. ));
  160. }
  161. Navigator.pop(context);
  162. setState(() {
  163. processing = false;
  164. });
  165. }
  166. },
  167. child: Text(
  168. "Crear Su Cita Ahora",
  169. style: style.copyWith(
  170. color: Colors.white,
  171. fontWeight: FontWeight.bold),
  172. ),
  173. ),
  174. ),
  175. ),
  176. ],
  177. ),
  178. ),
  179. ),
  180. );
  181. }
  182. @override
  183. void dispose() {
  184. _title.dispose();
  185. _description.dispose();
  186. _name.dispose();
  187. _number.dispose();
  188. _reason.dispose();
  189. super.dispose();
  190. }
  191. }
  192. // Funcionalidades para poder seleccionar horarios
  193. Future<TimeOfDay> _selectTime(BuildContext context) {
  194. final now = DateTime.now();
  195. return showTimePicker(
  196. context: context,
  197. initialTime: TimeOfDay(hour: now.hour, minute: now.minute),
  198. );
  199. }