123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- 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<StatefulWidget> viewOficina() {
- //no se que hago, quizas no lo necesite
- return null;
- }
- _VerOficinaState createState() => _VerOficinaState();
- }
-
- class _VerOficinaState extends State<VerOficina>{
- Map post = {};
- List<Oficina> _oficina;
- List<Horario> _horario;
- List<Especialista> _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<Oficina> 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 = _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 = _especialista;
- var especialistas = getEspecialistas(especialista);
-
- return Scaffold(
- appBar: AppBar(
- title: Text(name),
- centerTitle: true,
- ),
- body: Center(
- child: ListView(
- //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- new Card(
- color: Colors.red[300],
-
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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),
- ),
- ],
- ),
- ),
- ],
- ),
-
- ),
-
- );
- }
- }
|