Skip to content

Commit 6120344

Browse files
committed
lesson-31
1 parent 82a42b1 commit 6120344

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

world_time_app/lib/pages/home.dart

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

53
class Home extends StatefulWidget {
64
@override
@@ -9,27 +7,57 @@ class Home extends StatefulWidget {
97

108
class _HomeState extends State<Home> {
119

10+
Map data = {};
11+
1212
@override
1313
void initState() {
1414
super.initState();
1515
}
1616

1717
@override
1818
Widget build(BuildContext context) {
19+
20+
data = ModalRoute.of(context).settings.arguments;
21+
print(data);
22+
1923
return Scaffold(
24+
//appBar: AppBar(),
2025
body: SafeArea(
21-
child: Column(
22-
children: <Widget>[
23-
FlatButton.icon(
24-
onPressed: () {
25-
Navigator.pushNamed(context, '/location');
26-
},
27-
icon: Icon(Icons.edit_location),
28-
label: Text(
29-
'Edit Location'
30-
)
31-
)
32-
],
26+
child: Padding(
27+
padding: const EdgeInsets.fromLTRB(0, 120.0, 0, 0),
28+
child: Column(
29+
children: <Widget>[
30+
FlatButton.icon(
31+
onPressed: () {
32+
Navigator.pushNamed(context, '/location');
33+
},
34+
icon: Icon(Icons.edit_location),
35+
label: Text(
36+
'Edit Location'
37+
)
38+
),
39+
SizedBox(height: 20.0),
40+
Row(
41+
mainAxisAlignment: MainAxisAlignment.center,
42+
children: <Widget>[
43+
Text(
44+
data['location'],
45+
style: TextStyle(
46+
fontSize: 28.0,
47+
letterSpacing: 2.0,
48+
),
49+
),
50+
],
51+
),
52+
SizedBox(height: 20.0),
53+
Text(
54+
data['time'],
55+
style: TextStyle(
56+
fontSize: 66.0,
57+
)
58+
),
59+
],
60+
),
3361
),
3462
),
3563
);

world_time_app/lib/pages/loading.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ class Loading extends StatefulWidget {
88

99
class _LoadingState extends State<Loading> {
1010

11-
String time = 'loading';
12-
1311
void setupWorldTime() async {
1412
WorldTime instance = WorldTime(location: 'Berlin', flag: 'germany.png', url: 'Europe/Berlin');
1513
await instance.getTime();
16-
print(instance.time);
17-
setState(() {
18-
time = instance.time;
14+
Navigator.pushReplacementNamed(context, '/home', arguments: {
15+
'location': instance.location,
16+
'flag': instance.flag,
17+
'time': instance.time
1918
});
2019
}
2120

@@ -30,7 +29,7 @@ class _LoadingState extends State<Loading> {
3029
return Scaffold(
3130
body: Padding(
3231
padding: const EdgeInsets.all(50.0),
33-
child: Text(time),
32+
child: Text('loading'),
3433
),
3534
);
3635
}

world_time_app/lib/services/world_time.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:http/http.dart';
22
import 'dart:convert';
3+
import 'package:intl/intl.dart';
34

45
class WorldTime {
56

@@ -26,7 +27,7 @@ class WorldTime {
2627
now = now.add(Duration(hours: int.parse(offset)));
2728

2829
// set the time property
29-
time = now.toString();
30+
time = DateFormat.jm().format(now);
3031
}
3132
catch (e) {
3233
print(e);

world_time_app/pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ packages:
6060
url: "https://pub.dartlang.org"
6161
source: hosted
6262
version: "3.1.3"
63+
intl:
64+
dependency: "direct main"
65+
description:
66+
name: intl
67+
url: "https://pub.dartlang.org"
68+
source: hosted
69+
version: "0.15.8"
6370
matcher:
6471
dependency: transitive
6572
description:

world_time_app/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies:
2424
# Use with the CupertinoIcons class for iOS style icons.
2525
cupertino_icons: ^0.1.2
2626
http: ^0.12.0+2
27+
intl: ^0.15.8
2728

2829

2930
dev_dependencies:

0 commit comments

Comments
 (0)