No Description

ver_oficina.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. backgroundColor: Colors.blue[50],
  144. appBar: AppBar(
  145. title: Text(name),
  146. backgroundColor: Colors.red[300],
  147. centerTitle: true,
  148. ),
  149. body: Center(
  150. child: ListView(
  151. //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  152. children: [
  153. new Card(
  154. color: Colors.red[300],
  155. child: Column(
  156. mainAxisSize: MainAxisSize.min,
  157. children: <Widget>[
  158. ListTile(
  159. // leading: Icon(Icons.album),
  160. title: Text('Horario',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  161. subtitle: Text(
  162. 'Domingo: ' + '$domingo_horario'
  163. '\nLunes: ' + '$lunes_horario'
  164. '\nMartes: ' + '$martes_horario'
  165. '\nMiercoles: ' + '$miercoles_horario'
  166. '\nJueves: ' + '$jueves_horario'
  167. '\nViernes: ' + '$viernes_horario'
  168. '\nSabado: ' + '$sabado_horario',
  169. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  170. textAlign: TextAlign.center),
  171. ),
  172. Row(
  173. mainAxisAlignment: MainAxisAlignment.end,
  174. children: <Widget>[
  175. TextButton(
  176. child: const Text('Buscar Disponibilidad'),
  177. onPressed: () {
  178. Navigator.pushNamed(context, '/calendario');
  179. },
  180. ),
  181. const SizedBox(width: 8),
  182. ],
  183. ),
  184. ],
  185. ),
  186. ),
  187. new Card(
  188. color: Colors.red[300],
  189. child: Column(
  190. mainAxisSize: MainAxisSize.min,
  191. children: <Widget>[
  192. Row(
  193. mainAxisAlignment: MainAxisAlignment.center,
  194. children: <Widget>[
  195. TextButton(
  196. child: const Text('Especialidades \ndisponibles',
  197. style: TextStyle(fontWeight: FontWeight.bold,height: 1.5, fontSize: 36),
  198. textAlign: TextAlign.center),
  199. onPressed: () { /* ... */ },
  200. ),
  201. const SizedBox(width: 8),
  202. ],
  203. ),
  204. ListTile(
  205. subtitle: Text(
  206. '$especialistas',
  207. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  208. textAlign: TextAlign.center),
  209. ),
  210. ],
  211. ),
  212. ),
  213. new Card(
  214. color: Colors.red[300],
  215. child: Column(
  216. mainAxisSize: MainAxisSize.min,
  217. children: <Widget>[
  218. ListTile(
  219. title: Text('Direccion',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  220. subtitle: Text('$address',
  221. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  222. textAlign: TextAlign.center),
  223. ),
  224. Row(
  225. mainAxisAlignment: MainAxisAlignment.end,
  226. children: <Widget>[
  227. TextButton(
  228. child: const Text('Buscar en el mapa'),
  229. onPressed: () {
  230. setState(() async {
  231. String destinationLatitude = "18.39007092764153";
  232. String destinationLongitude = "-65.976216841223";
  233. String originlatitude = "18.418738017376207";
  234. String originlongitude = "-66.02565531285634";
  235. //const url = 'https://www.google.com/maps/@42.585444,13.007813,6z';
  236. const url = "https://www.google.com/maps/dir/?api=1&parameters&origin=18.418738017376207,-66.02565531285634&destination=18.39007092764153,-65.976216841223";
  237. if (await canLaunch(url)) {
  238. await launch(url);
  239. } else {
  240. throw 'Could not launch $url';
  241. }
  242. //String uri = "http://maps.google.com/maps?daddr=" + destinationLatitude + "," + destinationLongitude + " (" + "Doctor" + ")";
  243. //Intent intent;
  244. //intent.setAction(Action.ACTION_VIEW);
  245. //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
  246. //intent.setPackage("com.google.android.apps.maps");
  247. //startActivity(intent);
  248. //UIApplication.shared.openURL(URL(string:"https://www.google.com/maps/@42.585444,13.007813,6z")!);
  249. });
  250. },
  251. ),
  252. const SizedBox(width: 8),
  253. ],
  254. ),
  255. ],
  256. ),
  257. ),
  258. new Card(
  259. color: Colors.red[300],
  260. child: Column(
  261. mainAxisSize: MainAxisSize.min,
  262. children: <Widget>[
  263. ListTile(
  264. title: Text('Contacto',style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 36),textAlign: TextAlign.center),
  265. subtitle: Text("Telefono: \n "
  266. "$telephone \n "
  267. "\n"
  268. "Email: \n "
  269. "$email",
  270. style: TextStyle(fontWeight: FontWeight.bold,height: 2, fontSize: 12),
  271. textAlign: TextAlign.center),
  272. ),
  273. ],
  274. ),
  275. ),
  276. ],
  277. ),
  278. ),
  279. );
  280. }
  281. }