Aucune description

ver_oficina.dart 11KB

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