-
Notifications
You must be signed in to change notification settings - Fork 0
/
46-Futures-3-ParseJSON.dart
58 lines (46 loc) · 1.38 KB
/
46-Futures-3-ParseJSON.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// FUTURES - só existe em Dart, JavaScript (Promises)
// bom para contato com servicos externos, api. Coisas que dependem de rede, imprevisiveis de saber se vao funcionar ou nao
// Futures usam muita exception handling. Têm a ver com Assyncronous programming
// Funcoes que vao executar e que vao gerar resultado ou erro.
/*
import 'package:http/http.dart' as http;
void main() async {
var url = Uri.https('jsonplaceholder.typicode.com','users'); // retorna todos os registros
final response = await http.get(url);
print(response.body);
var url2 = Uri.https('jsonplaceholder.typicode.com','users/1'); // retorna o id 1 - veja abaixo a copia do site:
final response2 = await http.get(url2);
print(response2.body);
}
/*
Future<String> giveAResultAfter2Sec() {
return Future.delayed(Duration(seconds: 2), () async {return 'Hey!!!!!!!!!';});
}
*/
/*
* {
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}
Documentation
*/
*/