Kaynağa Gözat

Added: click en una Oficina de la lista te lleva a una pagina para ver su informacion

Oniel Mendez 4 yıl önce
ebeveyn
işleme
44ad4ba069

+ 5
- 1
fast_med_flutter/lib/main.dart Dosyayı Görüntüle

@@ -1,9 +1,11 @@
1 1
 import 'package:fast_med_flutter/routes/home.dart';
2 2
 import 'package:fast_med_flutter/routes/ver_oficinas.dart';
3
+import 'package:fast_med_flutter/routes/ver_oficina.dart';
3 4
 import 'package:fast_med_flutter/routes/calendario.dart';
4 5
 import 'package:fast_med_flutter/routes/main.dart';
5 6
 import 'package:fast_med_flutter/routes/register.dart';
6 7
 import 'package:fast_med_flutter/routes/welcome.dart';
8
+import 'package:fast_med_flutter/routes/album.dart';
7 9
 import 'package:flutter/material.dart';
8 10
 
9 11
 void main() => runApp(MaterialApp(
@@ -11,9 +13,11 @@ void main() => runApp(MaterialApp(
11 13
     routes: {
12 14
       '/home': (context) => Home(),
13 15
       '/verOficinas': (context) => VerOficinas(),
16
+      '/ver/oficina': (context) => VerOficina(),
14 17
       '/calendario': (context) => Calendario(),
15 18
       '/welcome': (context) => WelcomePage(),
16 19
       '/register': (context) => RegisterPage(),
17
-      '/MyApp': (context) => MyApp(),
20
+          '/MyApp': (context) => MyApp(),
21
+          '/album': (context) => album(),
18 22
     }
19 23
 ));

+ 85
- 0
fast_med_flutter/lib/routes/album.dart Dosyayı Görüntüle

@@ -0,0 +1,85 @@
1
+import 'dart:async';
2
+import 'dart:convert';
3
+import 'dart:io';
4
+
5
+import 'package:flutter/material.dart';
6
+import 'package:flutter/services.dart';
7
+import 'package:http/http.dart' as http;
8
+
9
+Future<Oficina> fetchOficina() async {
10
+  final response =
11
+  await http.get('https://ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php');
12
+
13
+  if (response.statusCode == 200) {
14
+    return Oficina.fromJson(jsonDecode(response.body));
15
+  } else {
16
+    throw Exception('Failed to load album');
17
+  }
18
+}
19
+
20
+class Oficina {
21
+  String id;
22
+  String name;
23
+
24
+  Oficina({this.id, this.name});
25
+
26
+  factory Oficina.fromJson(Map<String, dynamic> json) {
27
+    return Oficina (
28
+      id :json['id'],
29
+      name: json['name'],
30
+    );
31
+  }
32
+}
33
+
34
+
35
+Future<void> main() async {
36
+  runApp(album());
37
+}
38
+class album extends StatefulWidget {
39
+
40
+  album({Key key}) : super(key: key);
41
+
42
+  @override
43
+  _MyAppState2 createState() => _MyAppState2();
44
+}
45
+
46
+
47
+class _MyAppState2 extends State<album> {
48
+  Future<Oficina> futureOficina;
49
+
50
+  @override
51
+  void initState() {
52
+    super.initState();
53
+    futureOficina = fetchOficina();
54
+  }
55
+
56
+  @override
57
+  Widget build(BuildContext context) {
58
+    return MaterialApp(
59
+      title: 'Fetch Data Example',
60
+      theme: ThemeData(
61
+        primarySwatch: Colors.blue,
62
+      ),
63
+      home: Scaffold(
64
+        appBar: AppBar(
65
+          title: Text('Fetch Data Example'),
66
+        ),
67
+        body: Center(
68
+          child: FutureBuilder<Oficina>(
69
+            future: futureOficina,
70
+            builder: (context, snapshot) {
71
+              if (snapshot.hasData) {
72
+                return Text(snapshot.data.name);
73
+              } else if (snapshot.hasError) {
74
+                return Text("${snapshot.error}");
75
+              }
76
+
77
+              // By default, show a loading spinner.
78
+              return CircularProgressIndicator();
79
+            },
80
+          ),
81
+        ),
82
+      ),
83
+    );
84
+  }
85
+}

+ 18
- 62
fast_med_flutter/lib/routes/home.dart Dosyayı Görüntüle

@@ -1,10 +1,14 @@
1 1
 import 'package:flutter/material.dart';
2
+import '../widgets/functions.dart';
2 3
 
3 4
 class Home extends StatefulWidget{
4 5
   @override
5 6
   _HomeState createState() => _HomeState();
6 7
 }
7 8
 
9
+
10
+
11
+
8 12
 class _HomeState extends State<Home>{
9 13
   @override
10 14
   Widget build(BuildContext context){
@@ -14,69 +18,21 @@ class _HomeState extends State<Home>{
14 18
         centerTitle: true,
15 19
       ),
16 20
       body: Center(
17
-        child: Column(
18
-          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
21
+        child: ListView(
22
+          //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
19 23
           children: [
20
-            new FlatButton(
21
-              minWidth: 300.0,
22
-              height: 100.0,
23
-              onPressed: (){
24
-                Navigator.pushNamed(context, '/verOficinas');
25
-              },
26
-              child: Text('Ver Oficinas',
27
-                style: TextStyle(fontSize: 36),
28
-              ),
29
-              color: Colors.purple,
30
-
31
-            ),
32
-            new FlatButton(
33
-              minWidth: 300.0,
34
-              height: 100.0,
35
-              onPressed: (){
36
-                Navigator.pushNamed(context, '/calendario');
37
-              },
38
-              child: Text('Calendario',
39
-                style: TextStyle(fontSize: 36),
40
-              ),
41
-              color: Colors.purple,
42
-
43
-            ),
44
-            new FlatButton(
45
-              minWidth: 300.0,
46
-              height: 100.0,
47
-              onPressed: (){
48
-                Navigator.pushNamed(context, '/register');
49
-              },
50
-              child: Text('register',
51
-                style: TextStyle(fontSize: 36),
52
-              ),
53
-              color: Colors.purple,
54
-
55
-            ),
56
-            new FlatButton(
57
-              minWidth: 300.0,
58
-              height: 100.0,
59
-              onPressed: (){
60
-                Navigator.pushNamed(context, '/welcome');
61
-              },
62
-              child: Text('welcome',
63
-                style: TextStyle(fontSize: 36),
64
-              ),
65
-              color: Colors.purple,
66
-
67
-            ),
68
-            new FlatButton(
69
-              minWidth: 300.0,
70
-              height: 100.0,
71
-              onPressed: (){
72
-                Navigator.pushNamed(context, '/MyApp');
73
-              },
74
-              child: Text('MyApp',
75
-                style: TextStyle(fontSize: 36),
76
-              ),
77
-              color: Colors.purple,
78
-
79
-            ),
24
+            newButton(context,'/verOficinas','Ver Oficinas'),
25
+            spaceBetween(),
26
+            // newButton(context,'/calendario','Calendario'),
27
+            // spaceBetween(),
28
+            // newButton(context,'/register','Register'),
29
+            // spaceBetween(),
30
+            // newButton(context,'/welcome','Welcome'),
31
+            // spaceBetween(),
32
+            // newButton(context,'/MyApp','MyApp'),
33
+            // spaceBetween(),
34
+            // newButton(context,'/album','Ver Oficinas 2: electr'),
35
+            // spaceBetween(),
80 36
             ],
81 37
         ),
82 38
 

+ 276
- 0
fast_med_flutter/lib/routes/ver_oficina.dart Dosyayı Görüntüle

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

+ 15
- 27
fast_med_flutter/lib/routes/ver_oficinas.dart Dosyayı Görüntüle

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
2 2
 import '../widgets/DataTableMySqlDemo/Oficina.dart';
3 3
 import '../widgets/DataTableMySqlDemo/Services.dart';
4 4
 import 'dart:async';
5
+import '../widgets/functions.dart';
5 6
 
6 7
 class VerOficinas extends StatefulWidget{
7 8
   VerOficinas() : super();
@@ -58,34 +59,21 @@ class _VerOficinasState extends State<VerOficinas>{
58 59
         backgroundColor: Colors.purple,
59 60
 
60 61
       ),
61
-      body: Center(
62
-          child: Column(
63
-            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
64
-            children: lista.map((Oficina data) {
65
-              return FlatButton(
66
-                minWidth: 300.0,
67
-                height: 100.0,
68
-                child: Text(data.name,
69
-                style: TextStyle(fontSize: 36),
70
-                ),
71
-                onPressed: () {
72
-                  print(data.name);
73
-                },
74
-                padding: new EdgeInsets.all(0.0),
75
-                color: Colors.purple,
76
-
77
-              );
78
-            }).toList(),
79
-          ),
80
-          // child: FlatButton(
81
-          //   onPressed: (){
82
-          //     _getOficinas();
83
-          //   },
84
-          //   child: Text('Ver Oficinas'),
85
-          //   color: Colors.purple,
86
-          // )
62
+      body: ListView.builder(
63
+        itemCount: lista.length,
64
+        itemBuilder: (context, index){
65
+          return Card(
66
+          child: ListTile(
67
+            onTap: () {
68
+              Navigator.pushNamed(context, "/ver/oficina", arguments:{
69
+                'id' : lista[index].id,
70
+              });
71
+            },
72
+            title: Text(lista[index].name),
73
+          )
74
+          );
75
+        }
87 76
       ),
88
-
89 77
     );
90 78
   }
91 79
 }

+ 32
- 0
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Especialista.dart Dosyayı Görüntüle

@@ -0,0 +1,32 @@
1
+class Especialista {
2
+  String id;
3
+  String oficina_id;
4
+  String name;
5
+  String specialty;
6
+  String telephone;
7
+  String email;
8
+
9
+  Especialista({this.id, this.oficina_id, this.name, this.specialty, this.telephone, this.email});
10
+
11
+  factory Especialista.allFromJson(Map<String, dynamic> json) {
12
+    return Especialista (
13
+      id :json['id'] as String,
14
+      oficina_id: json['oficina_id'] as String,
15
+      name: json['name'] as String,
16
+      specialty: json['specialty'] as String,
17
+      telephone: json['telephone'] as String,
18
+      email: json['email'] as String,
19
+    );
20
+  }
21
+
22
+  factory Especialista.infoFromJson(Map<String, dynamic> json) {
23
+    return Especialista (
24
+      id :json['id'] as String,
25
+      oficina_id: json['oficina_id'] as String,
26
+      name: json['name'] as String,
27
+      specialty: json['specialty'] as String,
28
+      telephone: json['telephone'] as String,
29
+      email: json['email'] as String,
30
+    );
31
+  }
32
+}

+ 29
- 0
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Horario.dart Dosyayı Görüntüle

@@ -0,0 +1,29 @@
1
+class Horario {
2
+  String id;
3
+  String oficina_id;
4
+  String dia_semana;
5
+  String open_time;
6
+  String close_time;
7
+
8
+  Horario({this.id, this.oficina_id, this.dia_semana, this.open_time, this.close_time});
9
+
10
+  factory Horario.allFromJson(Map<String, dynamic> json) {
11
+    return Horario (
12
+      id :json['id'] as String,
13
+      oficina_id: json['oficina_id'] as String,
14
+      dia_semana: json['dia_semana'] as String,
15
+      open_time: json['open_time'] as String,
16
+      close_time: json['close_time'] as String,
17
+    );
18
+  }
19
+
20
+  factory Horario.infoFromJson(Map<String, dynamic> json) {
21
+    return Horario (
22
+      id :json['id'] as String,
23
+      oficina_id: json['oficina_id'] as String,
24
+      dia_semana: json['dia_semana'] as String,
25
+      open_time: json['open_time'] as String,
26
+      close_time: json['close_time'] as String,
27
+    );
28
+  }
29
+}

+ 18
- 2
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Oficina.dart Dosyayı Görüntüle

@@ -1,13 +1,29 @@
1 1
 class Oficina {
2 2
   String id;
3 3
   String name;
4
+  String address;
5
+  String telephone;
6
+  String email;
4 7
 
5
-  Oficina({this.id, this.name});
8
+  Oficina({this.id, this.name, this.address, this.telephone, this.email});
6 9
 
7
-  factory Oficina.fromJson(Map<String, dynamic> json) {
10
+  factory Oficina.allFromJson(Map<String, dynamic> json) {
8 11
     return Oficina (
9 12
       id :json['id'] as String,
10 13
       name: json['name'] as String,
14
+      address: json['address'] as String,
15
+      telephone: json['telephone'] as String,
16
+      email: json['email'] as String,
17
+    );
18
+  }
19
+
20
+  factory Oficina.infoFromJson(Map<String, dynamic> json) {
21
+    return Oficina (
22
+      id :json['id'] as String,
23
+      name: json['name'] as String,
24
+      address: json['address'] as String,
25
+      telephone: json['telephone'] as String,
26
+      email: json['email'] as String,
11 27
     );
12 28
   }
13 29
 }

+ 77
- 19
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Services.dart Dosyayı Görüntüle

@@ -1,46 +1,104 @@
1 1
 import 'dart:convert';
2
+import 'package:fast_med_flutter/widgets/DataTableMySqlDemo/Horario.dart';
3
+import 'package:fast_med_flutter/widgets/DataTableMySqlDemo/Especialista.dart';
2 4
 import 'package:http/http.dart'
3 5
   as http;
4 6
 import 'Oficina.dart';
5 7
 
6 8
 class Services {
7
-  static const URL = 'https://ada.uprrp.edu/~oniel.mendez2/json/oficinas.php';
8
-  static const URL_GET_ALL = 'ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php';
9
-  static const URL_LOCAL = 'http://localhost/test/getOficinas.json';
10
-  static const _GET_ALL = "GET_ALL";
9
+  static const URL_GET_ALL = 'http://ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php';
10
+  static const URL_OFICINA_GET_BY_ID = 'https://ada.uprrp.edu/~oniel.mendez2/json/getOficinaByID.php';
11
+  static const URL_HORARIO = 'https://ada.uprrp.edu/~oniel.mendez2/json/getHorario.php';
12
+  static const URL_ESPECIALISTA = 'https://ada.uprrp.edu/~oniel.mendez2/json/getEspecialista.php';
13
+  //static const _GET_ALL = "GET_ALL";
11 14
 
12 15
   //get all oficinas
13 16
   static Future<List<Oficina>> getOficinas() async {
14 17
     try {
15
-      var map = Map<String, dynamic>();
16
-      map['action'] = _GET_ALL;
17
-      //print('antes');
18 18
       final response = await http.get(URL_GET_ALL);
19
-      // print('despues');
20
-      // print('getOficinas Response: ${response.body}');
21 19
       if (200 == response.statusCode) {
22
-        List<Oficina> list = parseResponse(response.body);
20
+        final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
21
+        List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
22
+        return list;
23
+      } else {
24
+        final response = '[{"id":"1","name":"error."},{"id":"2","name":"el codigo"},{"id":"3","name":"!=200"}]';
25
+        final parsed = json.decode(response).cast<Map<String, dynamic>>();
26
+        List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
27
+        return list; // return an empty list on exception/error
28
+      }
29
+    } catch (e) {
30
+      final response = '[{"id":"1","name":"oficina 1,"telephone":"787","address":"Carretera ##","email":"email@domain.com""},'
31
+                        '{"id":"2","name":"oficina 2","telephone":"787","address":"Carretera ##","email":"email@domain.com"},'
32
+                        '{"id":"3","name":"oficina 3","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
33
+      final parsed = json.decode(response).cast<Map<String, dynamic>>();
34
+      List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
35
+      return list; // return an empty list on exception/error
36
+    }
37
+  }
23 38
 
39
+  static Future<List<Oficina>> getOficina(id) async {
40
+    try {
41
+      final response = await http.post(URL_OFICINA_GET_BY_ID, body: {'id': id});
42
+      if (200 == response.statusCode) {
43
+        final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
44
+        List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
24 45
         return list;
25 46
       } else {
26
-        final response = '[{"id":"1","name":"no"},{"id":"2","name":"respondio"},{"id":"3","name":"code: 200"}]';
27
-        List<Oficina> list = parseResponse(response);
47
+        final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
48
+        final parsed = json.decode(response).cast<Map<String, dynamic>>();
49
+        List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
28 50
         return list; // return an empty list on exception/error
29 51
       }
30 52
     } catch (e) {
31
-      final response = '[{"id":"1","name":"este"},{"id":"2","name":"es el"},{"id":"3","name":"catch(e)"}]';
32
-      List<Oficina> list = parseResponse(response);
53
+      final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
54
+      final parsed = json.decode(response).cast<Map<String, dynamic>>();
55
+      List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
33 56
       return list; // return an empty list on exception/error
34 57
     }
35 58
   }
36 59
 
37
-  static List<Oficina> parseResponse(String responseBody) {
38
-    final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
39
-    return parsed.map<Oficina>((json) => Oficina.fromJson(json)).toList();
60
+  //para conseguir el horario de una oficina
61
+  static Future<List<Horario>> getHorario(id) async {
62
+    try {
63
+      final response = await http.post(URL_HORARIO, body: {'id': id});
64
+      if (200 == response.statusCode && response != null) {
65
+        final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
66
+        List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
67
+        return list;
68
+      } else {
69
+        final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
70
+        final parsed = json.decode(response).cast<Map<String, dynamic>>();
71
+        List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
72
+        return list; // return an empty list on exception/error
73
+      }
74
+    } catch (e) {
75
+      final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
76
+      final parsed = json.decode(response).cast<Map<String, dynamic>>();
77
+      List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
78
+      return list; // return an empty list on exception/error
79
+    }
40 80
   }
41 81
 
42
-  Future<http.Response> fetchAlbum() {
43
-    return http.get('https://jsonplaceholder.typicode.com/albums/1');
82
+  //para conseguir especialistas que trabajen en una oficina
83
+  static Future<List<Especialista>> getEspecialista(id) async {
84
+    try {
85
+      final response = await http.post(URL_ESPECIALISTA, body: {'id': id});
86
+      if (200 == response.statusCode && response != null) {
87
+        final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
88
+        List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
89
+        return list;
90
+      } else {
91
+        final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
92
+        final parsed = json.decode(response).cast<Map<String, dynamic>>();
93
+        List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
94
+        return list; // return an empty list on exception/error
95
+      }
96
+    } catch (e) {
97
+      final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
98
+      final parsed = json.decode(response).cast<Map<String, dynamic>>();
99
+      List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
100
+      return list; // return an empty list on exception/error
101
+    }
44 102
   }
45 103
 
46 104
 }

+ 54
- 0
fast_med_flutter/lib/widgets/functions.dart Dosyayı Görüntüle

@@ -0,0 +1,54 @@
1
+import 'package:flutter/material.dart';
2
+
3
+FlatButton newButton(context,route,text){
4
+  return new FlatButton(
5
+    //minWidth: 300.0,
6
+    //height: 100.0,
7
+    onPressed: (){
8
+      Navigator.pushNamed(context, route);
9
+    },
10
+    child: Text(text,
11
+      style: TextStyle(fontSize: 36),
12
+    ),
13
+    color: Colors.purple,
14
+    //shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(50)),
15
+    padding: EdgeInsets.all(25),
16
+  );
17
+}
18
+FlatButton verOficinaButton(context,name){
19
+  return new FlatButton(
20
+        minWidth: 300.0,
21
+        height: 100.0,
22
+        child: Text(name,
23
+        style: TextStyle(fontSize: 36),
24
+        ),
25
+        onPressed: () {
26
+          print(name);
27
+        },
28
+        padding: new EdgeInsets.all(0.0),
29
+        color: Colors.purple,
30
+
31
+      );
32
+}
33
+
34
+SizedBox spaceBetween(){
35
+  return new SizedBox(height: 16);
36
+}
37
+List newButton2(context,route,text){
38
+  return [new FlatButton(
39
+          //minWidth: 300.0,
40
+          //height: 100.0,
41
+          onPressed: (){
42
+            Navigator.pushNamed(context, route);
43
+          },
44
+          child: Text(text,
45
+            style: TextStyle(fontSize: 36),
46
+          ),
47
+          color: Colors.purple,
48
+          //shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(50)),
49
+          padding: EdgeInsets.all(25),
50
+        )
51
+    ,
52
+    new SizedBox(height: 16)
53
+  ];
54
+}

+ 2
- 1
fast_med_flutter/pubspec.yaml Dosyayı Görüntüle

@@ -34,7 +34,8 @@ dependencies:
34 34
 
35 35
   #
36 36
   http: ^0.12.2
37
-
37
+assets:
38
+  - assets/raw/certificate.pem
38 39
 dev_dependencies:
39 40
   flutter_test:
40 41
     sdk: flutter