No Description

add_event.dart 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. import 'dart:convert';
  7. class AddEventPage extends StatefulWidget {
  8. final EventModel note;
  9. const AddEventPage({Key key, this.note}) : super(key: key);
  10. @override
  11. _AddEventPageState createState() => _AddEventPageState();
  12. }
  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. TextEditingController _date;
  21. TextEditingController _time;
  22. DateTime _eventDate;
  23. DateTime _eventTime;
  24. DateTime selectedDate = DateTime.now();
  25. List data;
  26. final _formKey = GlobalKey<FormState>();
  27. final _key = GlobalKey<ScaffoldState>();
  28. bool processing;
  29. @override
  30. void initState() {
  31. super.initState();
  32. _title = TextEditingController(text: widget.note != null ? widget.note.title : "");
  33. _description = TextEditingController(text: widget.note != null ? widget.note.description : "");
  34. //_name = TextEditingController(text: widget.note != null ? widget.note.name : "");
  35. //_number = TextEditingController(text: widget.note != null ? widget.note.number : "");
  36. // _reason = TextEditingController(text: widget.note != null ? widget.note.reason : "");
  37. //_date = TextEditingController(text: widget.note != null ? widget.note.eventDate;
  38. _eventDate = DateTime.now();
  39. //_eventTime = Time.now();
  40. processing = false;
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return Scaffold(
  45. appBar: AppBar(
  46. title: Text(widget.note != null ? "Edit Note" : "Crear Su Cita"),
  47. ),
  48. key: _key,
  49. body: Form(
  50. key: _formKey,
  51. child: Container(
  52. alignment: Alignment.center,
  53. child: ListView(
  54. children: <Widget>[
  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. Padding(
  70. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  71. child: TextFormField(
  72. controller: _number,
  73. validator: (value) =>
  74. (value.isEmpty) ? "Favor Anotar Numero de Telefono" : null,
  75. style: style,
  76. decoration: InputDecoration(
  77. labelText: "Numero de Telefono",
  78. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  79. ),
  80. ),
  81. Padding(
  82. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  83. child: TextFormField(
  84. controller: _reason,
  85. minLines: 3,
  86. maxLines: 5,
  87. validator: (value) =>
  88. (value.isEmpty) ? "Favor Explicar Razon Para La Cita" : null,
  89. style: style,
  90. decoration: InputDecoration(
  91. labelText: "Razones para su cita",
  92. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  93. ),
  94. ),
  95. const SizedBox(height: 10.0),
  96. ListTile(
  97. title: Text("Date (YYYY-MM-DD)"),
  98. subtitle: Text("${_eventDate.year} - ${_eventDate.month} - ${_eventDate.day}"),
  99. onTap: ()async{
  100. DateTime picked = await showDatePicker(context: context, initialDate: _eventDate, firstDate: DateTime(_eventDate.year-5), lastDate: DateTime(_eventDate.year+5));
  101. if(picked != null) {
  102. setState(() {
  103. _eventDate = picked;
  104. });
  105. }
  106. },
  107. ),
  108. ListTile(
  109. title: Text("Time (HH: mm)"),
  110. subtitle: Text("${_eventDate.hour} - ${_eventDate.minute} - ${_eventDate.second}"),
  111. onTap: ()async{
  112. final selectedTime = await _selectTime(context);
  113. if (selectedTime == null) return;
  114. print(selectedTime);
  115. setState(() {
  116. this.selectedDate = DateTime(
  117. selectedTime.hour,
  118. selectedTime.minute,
  119. );
  120. });
  121. }
  122. ),
  123. SizedBox(height: 10.0),
  124. processing
  125. ? Center(child: CircularProgressIndicator())
  126. : Padding(
  127. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  128. child: Material(
  129. elevation: 5.0,
  130. borderRadius: BorderRadius.circular(30.0),
  131. color: Theme.of(context).primaryColor,
  132. child: MaterialButton(
  133. onPressed: () async {
  134. if (_formKey.currentState.validate()) {
  135. setState(() {
  136. processing = true;
  137. });
  138. if(widget.note != null) {
  139. await eventDBS.updateData(widget.note.id,{
  140. "title": _title.text,
  141. "number": _number.text,
  142. "reason": _reason.text,
  143. "event_date": widget.note.eventDate,
  144. //"time": widget.note.DateTime,
  145. });
  146. }else{
  147. await eventDBS.createItem(EventModel(
  148. title: _title.text,
  149. description: _description.text,
  150. eventDate: _eventDate
  151. ));
  152. }
  153. Navigator.pop(context);
  154. setState(() {
  155. processing = false;
  156. });
  157. }
  158. },
  159. child: Text(
  160. "Crear Su Cita Ahora",
  161. style: style.copyWith(
  162. color: Colors.white,
  163. fontWeight: FontWeight.bold),
  164. ),
  165. ),
  166. ),
  167. ),
  168. ],
  169. ),
  170. ),
  171. ),
  172. );
  173. }
  174. @override
  175. void dispose() {
  176. _title.dispose();
  177. _description.dispose();
  178. super.dispose();
  179. }
  180. }
  181. Future<TimeOfDay> _selectTime(BuildContext context) {
  182. final now = DateTime.now();
  183. return showTimePicker(
  184. context: context,
  185. initialTime: TimeOfDay(hour: now.hour, minute: now.minute),
  186. );
  187. }
  188. Future<DateTime> _selectDateTime(BuildContext context) => showDatePicker(
  189. context: context,
  190. initialDate: DateTime.now().add(Duration(seconds: 1)),
  191. firstDate: DateTime.now(),
  192. lastDate: DateTime(2100),
  193. );