123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import 'package:fast_med_flutter/model/event.dart';
- import 'package:flutter/material.dart';
- import 'package:fast_med_flutter/res/event_firestore_service.dart';
- import 'package:http/http.dart' as http;
- import 'dart:async';
-
- class AddEventPage extends StatefulWidget {
- final EventModel note;
-
- const AddEventPage({Key key, this.note}) : super(key: key);
-
- @override
- _AddEventPageState createState() => _AddEventPageState();
- }
-
- //Controles de cada Evento que usaremos en todos los files
-
- class _AddEventPageState extends State<AddEventPage> {
- TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 20.0);
- TextEditingController _title;
- TextEditingController _description;
- TextEditingController _number;
- TextEditingController _name;
- TextEditingController _reason;
-
-
- DateTime _eventDate;
- DateTime _eventTime;
- DateTime selectedDate = DateTime.now();
- List data;
- List holidays;
- final _formKey = GlobalKey<FormState>();
- final _key = GlobalKey<ScaffoldState>();
- bool processing;
-
- @override
- void initState() {
- super.initState();
- _title = TextEditingController(text: widget.note != null ? widget.note.title : "");
- _description = TextEditingController(text: widget.note != null ? widget.note.description : "");
- _name = TextEditingController(text: widget.note != null ? widget.note.name : "");
- _number = TextEditingController(text: widget.note != null ? widget.note.number : "");
- _reason = TextEditingController(text: widget.note != null ? widget.note.reason : "");
- _eventDate = DateTime.now();
- _eventTime = DateTime.now();
- processing = false;
- }
-
- // Definimos el Formulario con cada parametro 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: <Widget>[
-
- // Area donde paciente anota su nombre. Si esta vacio no lo acepta.
-
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
- child: TextFormField(
- controller: _name,
- validator: (value) =>
- (value.isEmpty) ? "Favor Anotar Nombre del Paciente" : null,
- style: style,
- decoration: InputDecoration(
- labelText: "Nombre completo del paciente",
- filled: true,
- fillColor: Colors.white,
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
- ),
- ),
-
- //Area donde el paciente debe anotar su numero de telefono. Si esta vacio no lo acepta.
-
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
- child: TextFormField(
- controller: _number,
- validator: (value) =>
- (value.isEmpty) ? "Favor Anotar Numero de Telefono" : null,
- style: style,
- decoration: InputDecoration(
- labelText: "Numero de Telefono",
- border: OutlineInputBorder(borderRadius: BorderRadius.circular(10))),
- ),
- ),
-
- //Area donde el paciente explica la razon de su cita medica. Si esta vacio no lo acepta
-
- 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),
-
- //Area donde el paciente puede cambiar la fecha para la cita
-
- 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;
- });
- }
- },
- ),
-
- //Area donde el paciente puede elegir y cambiar la hora para la cita
-
- ListTile(
- title: Text("Time (HH: mm)"),
- subtitle: Text("${_eventDate.hour} - ${_eventDate.minute} - ${_eventDate.second}"),
- onTap: ()async{
- final selectedTime = await _selectTime(context);
- if (selectedTime == null) return;
- print(selectedTime);
-
- setState(() {
- this.selectedDate = DateTime(
- selectedTime.hour,
- selectedTime.minute,
- );
- });
- }
- ),
- SizedBox(height: 10.0),
-
- //Se define el envio de los parametros al usar el boton de Crear la Cita
-
- 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,
- "number": _number.text,
- "reason": _reason.text,
- "event_date": widget.note.eventDate,
- "time": widget.note.eventTime,
- });
- }else{
- await eventDBS.createItem(EventModel(
- title: _title.text,
- description: _description.text,
- name: _name.text,
- number: _number.text,
- reason: _reason.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();
- _name.dispose();
- _number.dispose();
- _reason.dispose();
- super.dispose();
- }
- }
-
- // Funcionalidades para poder seleccionar horarios
-
- Future<TimeOfDay> _selectTime(BuildContext context) {
- final now = DateTime.now();
-
- return showTimePicker(
- context: context,
- initialTime: TimeOfDay(hour: now.hour, minute: now.minute),
- );
- }
|