import 'package:fast_med_flutter/model/event.dart'; import 'package:flutter/material.dart'; import 'package:fast_med_flutter/res/event_firestore_service.dart'; import 'dart:async'; //File donde definimos los eventos del area de citas class AddEventPage extends StatefulWidget { final EventModel note; const AddEventPage({Key key, this.note}) : super(key: key); @override _AddEventPageState createState() => _AddEventPageState(); } //Definimos los controler de los eventos class _AddEventPageState extends State { TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0); TextEditingController _title; TextEditingController _description; TextEditingController _reason; DateTime _eventDate; DateTime selectedDate = DateTime.now(); List data; final _formKey = GlobalKey(); final _key = GlobalKey(); bool processing; //Controles donde escribimos el evento @override void initState() { super.initState(); _title = TextEditingController(text: widget.note != null ? widget.note.title : ""); _description = TextEditingController(text: widget.note != null ? widget.note.description : ""); _eventDate = DateTime.now(); processing = false; } //Construimos el UI para crear la cita @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.note != null ? "Edit Note" : "Crear Su Cita"), ), key: _key, body: Form( key: _formKey, child: Container( alignment: Alignment.center, child: ListView( children: [ //Area Donde el Paciente Anotara Su Cita Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: TextFormField( controller: _reason, minLines: 3, maxLines: 5, validator: (value) => (value.isEmpty) ? "Favor Explicar Razon Para La Cita" : null, style: style, decoration: InputDecoration( labelText: "Razones para su cita", border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))), ), ), const SizedBox(height: 10.0), ListTile( title: Text("Date (YYYY-MM-DD)"), subtitle: Text("${_eventDate.year} - ${_eventDate.month} - ${_eventDate.day}"), onTap: ()async{ DateTime picked = await showDatePicker(context: context, initialDate: _eventDate, firstDate: DateTime(_eventDate.year-5), lastDate: DateTime(_eventDate.year+5)); if(picked != null) { setState(() { _eventDate = picked; }); } }, ), SizedBox(height: 10.0), processing ? Center(child: CircularProgressIndicator()) : Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Material( elevation: 5.0, borderRadius: BorderRadius.circular(30.0), color: Theme.of(context).primaryColor, child: MaterialButton( onPressed: () async { if (_formKey.currentState.validate()) { setState(() { processing = true; }); if(widget.note != null) { await eventDBS.updateData(widget.note.id,{ "title": _title.text, "reason": _reason.text, "event_date": widget.note.eventDate, }); }else{ await eventDBS.createItem(EventModel( title: _title.text, description: _description.text, eventDate: _eventDate )); } Navigator.pop(context); setState(() { processing = false; }); } }, child: Text( "Crear Su Cita Ahora", style: style.copyWith( color: Colors.white, fontWeight: FontWeight.bold), ), ), ), ), ], ), ), ), ); } @override void dispose() { _title.dispose(); _description.dispose(); super.dispose(); } }