File tree Expand file tree Collapse file tree 4 files changed +34
-18
lines changed
Expand file tree Collapse file tree 4 files changed +34
-18
lines changed Original file line number Diff line number Diff line change @@ -7,27 +7,9 @@ class ChooseLocation extends StatefulWidget {
77
88class _ChooseLocationState extends State <ChooseLocation > {
99
10- void getData () async {
11-
12- // simulate network request for a username
13- String username = await Future .delayed (Duration (seconds: 3 ), () {
14- return 'yoshi' ;
15- });
16-
17- // simulate a network request to get the bio of that username
18- String bio = await Future .delayed (Duration (seconds: 2 ), () {
19- return 'vegan, musician & egg collector' ;
20- });
21-
22- print ('$username - $bio ' );
23-
24- }
25-
2610 @override
2711 void initState () {
2812 super .initState ();
29- getData ();
30- print ('hey there!' );
3113 }
3214
3315 @override
Original file line number Diff line number Diff line change 11import 'package:flutter/material.dart' ;
2+ import 'package:http/http.dart' ;
3+ import 'dart:convert' ;
24
35class Home extends StatefulWidget {
46 @override
@@ -7,6 +9,22 @@ class Home extends StatefulWidget {
79
810class _HomeState extends State <Home > {
911
12+ void getData () async {
13+
14+ Response response = await get ('https://jsonplaceholder.typicode.com/todos/1' );
15+ // print(response.body);
16+ Map data = jsonDecode (response.body);
17+ print (data);
18+ print (data['title' ]);
19+
20+ }
21+
22+ @override
23+ void initState () {
24+ super .initState ();
25+ getData ();
26+ }
27+
1028 @override
1129 Widget build (BuildContext context) {
1230 return Scaffold (
Original file line number Diff line number Diff line change @@ -46,6 +46,20 @@ packages:
4646 description: flutter
4747 source: sdk
4848 version: "0.0.0"
49+ http:
50+ dependency: "direct main"
51+ description:
52+ name: http
53+ url: "https://pub.dartlang.org"
54+ source: hosted
55+ version: "0.12.0+2"
56+ http_parser:
57+ dependency: transitive
58+ description:
59+ name: http_parser
60+ url: "https://pub.dartlang.org"
61+ source: hosted
62+ version: "3.1.3"
4963 matcher:
5064 dependency: transitive
5165 description:
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ dependencies:
2323 # The following adds the Cupertino Icons font to your application.
2424 # Use with the CupertinoIcons class for iOS style icons.
2525 cupertino_icons : ^0.1.2
26+ http : ^0.12.0+2
27+
2628
2729dev_dependencies :
2830 flutter_test :
You can’t perform that action at this time.
0 commit comments