No Description

add_event.dart 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 'dart:async';
  5. //File donde definimos los eventos del area de citas
  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. //Definimos los controler de los eventos
  13. class _AddEventPageState extends State<AddEventPage> {
  14. TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
  15. TextEditingController _title;
  16. TextEditingController _description;
  17. TextEditingController _reason;
  18. DateTime _eventDate;
  19. DateTime selectedDate = DateTime.now();
  20. List data;
  21. final _formKey = GlobalKey<FormState>();
  22. final _key = GlobalKey<ScaffoldState>();
  23. bool processing;
  24. //Controles donde escribimos el evento
  25. @override
  26. void initState() {
  27. super.initState();
  28. _title = TextEditingController(text: widget.note != null ? widget.note.title : "");
  29. _description = TextEditingController(text: widget.note != null ? widget.note.description : "");
  30. _eventDate = DateTime.now();
  31. processing = false;
  32. }
  33. //Construimos el UI para crear la cita
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. appBar: AppBar(
  38. title: Text(widget.note != null ? "Edit Note" : "Crear Su Cita"),
  39. ),
  40. key: _key,
  41. body: Form(
  42. key: _formKey,
  43. child: Container(
  44. alignment: Alignment.center,
  45. child: ListView(
  46. children: <Widget>[
  47. //Area Donde el Paciente Anotara Su Cita
  48. Padding(
  49. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
  50. child: TextFormField(
  51. controller: _reason,
  52. minLines: 3,
  53. maxLines: 5,
  54. validator: (value) =>
  55. (value.isEmpty) ? "Favor Explicar Razon Para La Cita" : null,
  56. style: style,
  57. decoration: InputDecoration(
  58. labelText: "Razones para su cita",
  59. border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
  60. ),
  61. ),
  62. const SizedBox(height: 10.0),
  63. ListTile(
  64. title: Text("Date (YYYY-MM-DD)"),
  65. subtitle: Text("${_eventDate.year} - ${_eventDate.month} - ${_eventDate.day}"),
  66. onTap: ()async{
  67. DateTime picked = await showDatePicker(context: context, initialDate: _eventDate, firstDate: DateTime(_eventDate.year-5), lastDate: DateTime(_eventDate.year+5));
  68. if(picked != null) {
  69. setState(() {
  70. _eventDate = picked;
  71. });
  72. }
  73. },
  74. ),
  75. SizedBox(height: 10.0),
  76. processing
  77. ? Center(child: CircularProgressIndicator())
  78. : Padding(
  79. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  80. child: Material(
  81. elevation: 5.0,
  82. borderRadius: BorderRadius.circular(30.0),
  83. color: Theme.of(context).primaryColor,
  84. child: MaterialButton(
  85. onPressed: () async {
  86. if (_formKey.currentState.validate()) {
  87. setState(() {
  88. processing = true;
  89. });
  90. if(widget.note != null) {
  91. await eventDBS.updateData(widget.note.id,{
  92. "title": _title.text,
  93. "reason": _reason.text,
  94. "event_date": widget.note.eventDate,
  95. });
  96. }else{
  97. await eventDBS.createItem(EventModel(
  98. title: _title.text,
  99. description: _description.text,
  100. eventDate: _eventDate
  101. ));
  102. }
  103. Navigator.pop(context);
  104. setState(() {
  105. processing = false;
  106. });
  107. }
  108. },
  109. child: Text(
  110. "Crear Su Cita Ahora",
  111. style: style.copyWith(
  112. color: Colors.white,
  113. fontWeight: FontWeight.bold),
  114. ),
  115. ),
  116. ),
  117. ),
  118. ],
  119. ),
  120. ),
  121. ),
  122. );
  123. }
  124. @override
  125. void dispose() {
  126. _title.dispose();
  127. _description.dispose();
  128. super.dispose();
  129. }
  130. }