import 'dart:convert'; import 'package:http/http.dart' as http; import 'Oficina.dart'; class Services { static const URL = 'https://ada.uprrp.edu/~oniel.mendez2/json/oficinas.php'; static const URL_GET_ALL = 'ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php'; static const URL_LOCAL = 'http://localhost/test/getOficinas.json'; static const _GET_ALL = "GET_ALL"; //get all oficinas static Future> getOficinas() async { try { var map = Map(); map['action'] = _GET_ALL; //print('antes'); final response = await http.get(URL_GET_ALL); // print('despues'); // print('getOficinas Response: ${response.body}'); if (200 == response.statusCode) { List list = parseResponse(response.body); return list; } else { final response = '[{"id":"1","name":"no"},{"id":"2","name":"respondio"},{"id":"3","name":"code: 200"}]'; List list = parseResponse(response); return list; // return an empty list on exception/error } } catch (e) { final response = '[{"id":"1","name":"este"},{"id":"2","name":"es el"},{"id":"3","name":"catch(e)"}]'; List list = parseResponse(response); return list; // return an empty list on exception/error } } static List parseResponse(String responseBody) { final parsed = json.decode(responseBody).cast>(); return parsed.map((json) => Oficina.fromJson(json)).toList(); } Future fetchAlbum() { return http.get('https://jsonplaceholder.typicode.com/albums/1'); } }