Skip to content

Commit 0493d74

Browse files
committed
lesson-26
1 parent 9aa1815 commit 0493d74

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

world_time_app/lib/pages/choose_location.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,9 @@ class ChooseLocation extends StatefulWidget {
77

88
class _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

world_time_app/lib/pages/home.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:http/http.dart';
3+
import 'dart:convert';
24

35
class Home extends StatefulWidget {
46
@override
@@ -7,6 +9,22 @@ class Home extends StatefulWidget {
79

810
class _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(

world_time_app/pubspec.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

world_time_app/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2729
dev_dependencies:
2830
flutter_test:

0 commit comments

Comments
 (0)