No Description

ver_oficina.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import 'package:flutter/material.dart';
  2. import '../widgets/DataTableMySqlDemo/Oficina.dart';
  3. import '../widgets/DataTableMySqlDemo/Horario.dart';
  4. import '../widgets/DataTableMySqlDemo/Especialista.dart';
  5. import '../widgets/DataTableMySqlDemo/Services.dart';
  6. import 'dart:async';
  7. import '../widgets/functions.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:url_launcher/url_launcher.dart';
  10. class VerOficina extends StatefulWidget{
  11. VerOficina() : super();
  12. final String title = 'Oficina';
  13. @override
  14. State<StatefulWidget> viewOficina() {
  15. //no se que hago, quizas no lo necesite
  16. return null;
  17. }
  18. _VerOficinaState createState() => _VerOficinaState();
  19. }
  20. class _VerOficinaState extends State<VerOficina>{
  21. Map post = {};
  22. List<Oficina> _oficina;
  23. List<Horario> _horario;
  24. List<Especialista> _especialista;
  25. @override
  26. void initState() {
  27. super.initState();
  28. _oficina = [];
  29. _getOficina();
  30. _horario = [];
  31. _getHorario();
  32. _especialista = [];
  33. _getEspecialista();
  34. }
  35. _getOficina() {
  36. return _oficina;
  37. }
  38. _getHorario() {
  39. return _horario;
  40. }
  41. _getEspecialista() {
  42. return _especialista;
  43. }
  44. //funcion
  45. //recibe Horario para regresar la horas de entrada y salida
  46. String getHoras(Horario horario) {
  47. var open_time = horario.open_time;
  48. var close_time = horario.close_time;
  49. if (open_time == close_time
  50. && open_time == '00:00:00'){
  51. return 'Cerrado';
  52. }
  53. var open_hour = int.parse(open_time.substring(0,2));
  54. var open_minutes = open_time.substring(3,5);
  55. //var open_minutes;
  56. var close_hour = int.parse(close_time.substring(0,2));
  57. var close_minutes = open_time.substring(3,5);
  58. // ver si la hora de abrir es AM o PM
  59. if (open_hour==12){
  60. open_time = open_time.substring(0,5) + ' PM';
  61. }else if (open_hour>12){
  62. open_time = (open_hour % 12).toString() + ':' + open_minutes + ' PM';
  63. }else{
  64. open_time = (open_hour % 12).toString() + ':' + open_minutes + ' AM';
  65. }
  66. // ver si la hora de cerrar es AM o PM
  67. if (close_hour==12){
  68. close_time = close_time.substring(0,5) + ' PM';
  69. }else if (close_hour>12){
  70. close_time = (close_hour % 12).toString() + ':' + close_minutes + ' PM';
  71. }else{
  72. close_time = (close_hour % 12).toString() + ':' + close_minutes + ' AM';
  73. }
  74. return open_time + ' - ' + close_time;
  75. }
  76. String getEspecialistas(List especialistas) {
  77. if(especialistas.length > 0 && especialistas[0].specialty.toString() != 'null'){
  78. var str = "";
  79. especialistas.forEach((especialista){
  80. str = str + especialista.specialty.toString() + '\n';
  81. });
  82. return str;
  83. }
  84. return "No hay especialistas";
  85. }
  86. @override
  87. Widget build(BuildContext context){
  88. post = ModalRoute.of(context).settings.arguments;
  89. Services.getOficina(post['id']).then((Oficina) {
  90. setState(() {
  91. _oficina = Oficina;
  92. });
  93. });
  94. Services.getHorario(post['id']).then((Horario) {
  95. setState(() {
  96. _horario = Horario;
  97. });
  98. });
  99. Services.getEspecialista(post['id']).then((Especialista) {
  100. setState(() {
  101. _especialista = Especialista;
  102. });
  103. });
  104. List<Oficina> lista = _oficina;
  105. var name = 'Cargando...';
  106. var telephone = 'Cargando...';
  107. var address = 'Cargando...';
  108. var email = 'Cargando...';
  109. if (lista.length > 0){
  110. name = lista[0].name;
  111. telephone = lista[0].telephone;
  112. address = lista[0].address;
  113. email = lista[0].email;
  114. }
  115. List<Horario> horario = _horario;
  116. var domingo_horario = 'Cargando...';
  117. var lunes_horario = 'Cargando...';
  118. var martes_horario = 'Cargando...';
  119. var miercoles_horario = 'Cargando...';
  120. var jueves_horario = 'Cargando...';
  121. var viernes_horario = 'Cargando...';
  122. var sabado_horario = 'Cargando...';
  123. if(horario.length == 7){
  124. domingo_horario = getHoras(horario[0]);
  125. lunes_horario = getHoras(horario[1]);
  126. martes_horario = getHoras(horario[2]);
  127. miercoles_horario = getHoras(horario[3]);
  128. jueves_horario = getHoras(horario[4]);
  129. viernes_horario = getHoras(horario[5]);
  130. sabado_horario = getHoras(horario[6]);
  131. }else{
  132. domingo_horario = 'Error';
  133. lunes_horario = 'Error';
  134. martes_horario = 'Error';
  135. miercoles_horario = 'Error';
  136. jueves_horario = 'Error';
  137. viernes_horario = 'Error';
  138. sabado_horario = 'Error';
  139. }
  140. List<Especialista> especialista = _especialista;
  141. var especialistas = getEspecialistas(especialista);
  142. return Scaffold(
  143. appBar: AppBar(
  144. title: Text(name),
  145. centerTitle: true,
  146. ),
  147. body: Center(
  148. child: ListView(
  149. //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  150. children: [
  151. new Card(
  152. color: Colors.red[300],
  153. child: Column(
  154. mainAxisSize: MainAxisSize.min,
  155. children: <Widget>[
  156. ListTile(
  157. // leading: Icon(Icons.album),
  158. title: Text('Horario',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  159. subtitle: Text(
  160. 'Domingo: ' + '$domingo_horario'
  161. '\nLunes: ' + '$lunes_horario'
  162. '\nMartes: ' + '$martes_horario'
  163. '\nMiercoles: ' + '$miercoles_horario'
  164. '\nJueves: ' + '$jueves_horario'
  165. '\nViernes: ' + '$viernes_horario'
  166. '\nSabado: ' + '$sabado_horario',
  167. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  168. textAlign: TextAlign.center),
  169. ),
  170. Row(
  171. mainAxisAlignment: MainAxisAlignment.end,
  172. children: <Widget>[
  173. TextButton(
  174. child: const Text('Buscar Disponibilidad'),
  175. onPressed: () {
  176. Navigator.pushNamed(context, '/calendario');
  177. },
  178. ),
  179. const SizedBox(width: 8),
  180. ],
  181. ),
  182. ],
  183. ),
  184. ),
  185. new Card(
  186. color: Colors.red[300],
  187. child: Column(
  188. mainAxisSize: MainAxisSize.min,
  189. children: <Widget>[
  190. Row(
  191. mainAxisAlignment: MainAxisAlignment.center,
  192. children: <Widget>[
  193. TextButton(
  194. child: const Text('Especialidades \ndisponibles',
  195. style: TextStyle(fontWeight: FontWeight.bold,height: 1.5, fontSize: 36),
  196. textAlign: TextAlign.center),
  197. onPressed: () { /* ... */ },
  198. ),
  199. const SizedBox(width: 8),
  200. ],
  201. ),
  202. ListTile(
  203. subtitle: Text(
  204. '$especialistas',
  205. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  206. textAlign: TextAlign.center),
  207. ),
  208. ],
  209. ),
  210. ),
  211. new Card(
  212. color: Colors.red[300],
  213. child: Column(
  214. mainAxisSize: MainAxisSize.min,
  215. children: <Widget>[
  216. ListTile(
  217. title: Text('Direccion',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  218. subtitle: Text('$address',
  219. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  220. textAlign: TextAlign.center),
  221. ),
  222. Row(
  223. mainAxisAlignment: MainAxisAlignment.end,
  224. children: <Widget>[
  225. TextButton(
  226. child: const Text('Buscar en el mapa'),
  227. onPressed: () {
  228. setState(() async {
  229. String destinationLatitude = "18.39007092764153";
  230. String destinationLongitude = "-65.976216841223";
  231. String originlatitude = "18.418738017376207";
  232. String originlongitude = "-66.02565531285634";
  233. //const url = 'https://www.google.com/maps/@42.585444,13.007813,6z';
  234. const url = "https://www.google.com/maps/dir/?api=1&parameters&origin=18.418738017376207,-66.02565531285634&destination=18.39007092764153,-65.976216841223";
  235. if (await canLaunch(url)) {
  236. await launch(url);
  237. } else {
  238. throw 'Could not launch $url';
  239. }
  240. //String uri = "http://maps.google.com/maps?daddr=" + destinationLatitude + "," + destinationLongitude + " (" + "Doctor" + ")";
  241. //Intent intent;
  242. //intent.setAction(Action.ACTION_VIEW);
  243. //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
  244. //intent.setPackage("com.google.android.apps.maps");
  245. //startActivity(intent);
  246. //UIApplication.shared.openURL(URL(string:"https://www.google.com/maps/@42.585444,13.007813,6z")!);
  247. });
  248. },
  249. ),
  250. const SizedBox(width: 8),
  251. ],
  252. ),
  253. ],
  254. ),
  255. ),
  256. new Card(
  257. color: Colors.red[300],
  258. child: Column(
  259. mainAxisSize: MainAxisSize.min,
  260. children: <Widget>[
  261. ListTile(
  262. title: Text('Contacto',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  263. subtitle: Text("Telefono: \n "
  264. "$telephone \n "
  265. "\n"
  266. "Email: \n "
  267. "$email",
  268. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  269. textAlign: TextAlign.center),
  270. ),
  271. ],
  272. ),
  273. ),
  274. ],
  275. ),
  276. ),
  277. );
  278. }
  279. }