No Description

add_event.dart 5.4KB

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