import 'package:flutter/material.dart'; import '../widgets/DataTableMySqlDemo/Oficina.dart'; import '../widgets/DataTableMySqlDemo/Horario.dart'; import '../widgets/DataTableMySqlDemo/Especialista.dart'; import '../widgets/DataTableMySqlDemo/Services.dart'; import 'dart:async'; import '../widgets/functions.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; class VerOficina extends StatefulWidget{ VerOficina() : super(); final String title = 'Oficina'; @override State viewOficina() { //no se que hago, quizas no lo necesite return null; } _VerOficinaState createState() => _VerOficinaState(); } class _VerOficinaState extends State{ Map post = {}; List _oficina; List _horario; List _especialista; @override void initState() { super.initState(); _oficina = []; _getOficina(); _horario = []; _getHorario(); _especialista = []; _getEspecialista(); } _getOficina() { return _oficina; } _getHorario() { return _horario; } _getEspecialista() { return _especialista; } //funcion //recibe Horario para regresar la horas de entrada y salida String getHoras(Horario horario) { var open_time = horario.open_time; var close_time = horario.close_time; if (open_time == close_time && open_time == '00:00:00'){ return 'Cerrado'; } var open_hour = int.parse(open_time.substring(0,2)); var open_minutes = open_time.substring(3,5); //var open_minutes; var close_hour = int.parse(close_time.substring(0,2)); var close_minutes = open_time.substring(3,5); // ver si la hora de abrir es AM o PM if (open_hour==12){ open_time = open_time.substring(0,5) + ' PM'; }else if (open_hour>12){ open_time = (open_hour % 12).toString() + ':' + open_minutes + ' PM'; }else{ open_time = (open_hour % 12).toString() + ':' + open_minutes + ' AM'; } // ver si la hora de cerrar es AM o PM if (close_hour==12){ close_time = close_time.substring(0,5) + ' PM'; }else if (close_hour>12){ close_time = (close_hour % 12).toString() + ':' + close_minutes + ' PM'; }else{ close_time = (close_hour % 12).toString() + ':' + close_minutes + ' AM'; } return open_time + ' - ' + close_time; } String getEspecialistas(List especialistas) { if(especialistas.length > 0 && especialistas[0].specialty.toString() != 'null'){ var str = ""; especialistas.forEach((especialista){ str = str + especialista.specialty.toString() + '\n'; }); return str; } return "No hay especialistas"; } @override Widget build(BuildContext context){ post = ModalRoute.of(context).settings.arguments; Services.getOficina(post['id']).then((Oficina) { setState(() { _oficina = Oficina; }); }); Services.getHorario(post['id']).then((Horario) { setState(() { _horario = Horario; }); }); Services.getEspecialista(post['id']).then((Especialista) { setState(() { _especialista = Especialista; }); }); List lista = _oficina; var name = 'Cargando...'; var telephone = 'Cargando...'; var address = 'Cargando...'; var email = 'Cargando...'; if (lista.length > 0){ name = lista[0].name; telephone = lista[0].telephone; address = lista[0].address; email = lista[0].email; } List horario = _horario; var domingo_horario = 'Cargando...'; var lunes_horario = 'Cargando...'; var martes_horario = 'Cargando...'; var miercoles_horario = 'Cargando...'; var jueves_horario = 'Cargando...'; var viernes_horario = 'Cargando...'; var sabado_horario = 'Cargando...'; if(horario.length == 7){ domingo_horario = getHoras(horario[0]); lunes_horario = getHoras(horario[1]); martes_horario = getHoras(horario[2]); miercoles_horario = getHoras(horario[3]); jueves_horario = getHoras(horario[4]); viernes_horario = getHoras(horario[5]); sabado_horario = getHoras(horario[6]); }else{ domingo_horario = 'Error'; lunes_horario = 'Error'; martes_horario = 'Error'; miercoles_horario = 'Error'; jueves_horario = 'Error'; viernes_horario = 'Error'; sabado_horario = 'Error'; } List especialista = _especialista; var especialistas = getEspecialistas(especialista); return Scaffold( backgroundColor: Colors.blue[50], appBar: AppBar( title: Text(name), backgroundColor: Colors.red[300], centerTitle: true, ), body: Center( child: ListView( //mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ new Card( color: Colors.red[300], child: Column( mainAxisSize: MainAxisSize.min, children: [ ListTile( // leading: Icon(Icons.album), title: Text('Horario',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center), subtitle: Text( 'Domingo: ' + '$domingo_horario' '\nLunes: ' + '$lunes_horario' '\nMartes: ' + '$martes_horario' '\nMiercoles: ' + '$miercoles_horario' '\nJueves: ' + '$jueves_horario' '\nViernes: ' + '$viernes_horario' '\nSabado: ' + '$sabado_horario', style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12), textAlign: TextAlign.center), ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ TextButton( child: const Text('Buscar Disponibilidad'), onPressed: () { Navigator.pushNamed(context, '/calendario'); }, ), const SizedBox(width: 8), ], ), ], ), ), new Card( color: Colors.red[300], child: Column( mainAxisSize: MainAxisSize.min, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ TextButton( child: const Text('Especialidades \ndisponibles', style: TextStyle(fontWeight: FontWeight.bold,height: 1.5, fontSize: 36), textAlign: TextAlign.center), onPressed: () { /* ... */ }, ), const SizedBox(width: 8), ], ), ListTile( subtitle: Text( '$especialistas', style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12), textAlign: TextAlign.center), ), ], ), ), new Card( color: Colors.red[300], child: Column( mainAxisSize: MainAxisSize.min, children: [ ListTile( title: Text('Direccion',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center), subtitle: Text('$address', style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12), textAlign: TextAlign.center), ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ TextButton( child: const Text('Buscar en el mapa'), onPressed: () { setState(() async { String destinationLatitude = "18.39007092764153"; String destinationLongitude = "-65.976216841223"; String originlatitude = "18.418738017376207"; String originlongitude = "-66.02565531285634"; //const url = 'https://www.google.com/maps/@42.585444,13.007813,6z'; const url = "https://www.google.com/maps/dir/?api=1¶meters&origin=18.418738017376207,-66.02565531285634&destination=18.39007092764153,-65.976216841223"; if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } //String uri = "http://maps.google.com/maps?daddr=" + destinationLatitude + "," + destinationLongitude + " (" + "Doctor" + ")"; //Intent intent; //intent.setAction(Action.ACTION_VIEW); //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); //intent.setPackage("com.google.android.apps.maps"); //startActivity(intent); //UIApplication.shared.openURL(URL(string:"https://www.google.com/maps/@42.585444,13.007813,6z")!); }); }, ), const SizedBox(width: 8), ], ), ], ), ), new Card( color: Colors.red[300], child: Column( mainAxisSize: MainAxisSize.min, children: [ ListTile( title: Text('Contacto',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center), subtitle: Text("Telefono: \n " "$telephone \n " "\n" "Email: \n " "$email", style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12), textAlign: TextAlign.center), ), ], ), ), ], ), ), ); } }