Skip to content

Commit 697020b

Browse files
committed
lesson-35
1 parent 79b7b67 commit 697020b

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

world_time_app/lib/pages/choose_location.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ class _ChooseLocationState extends State<ChooseLocation> {
1919
WorldTime(url: 'Asia/Jakarta', location: 'Jakarta', flag: 'indonesia.png'),
2020
];
2121

22+
void updateTime(index) async {
23+
WorldTime instance = locations[index];
24+
await instance.getTime();
25+
Navigator.pop(context, {
26+
'location': instance.location,
27+
'time': instance.time,
28+
'flag': instance.flag,
29+
'isDaytime': instance.isDaytime,
30+
});
31+
}
32+
2233
@override
2334
void initState() {
2435
super.initState();
@@ -41,7 +52,9 @@ class _ChooseLocationState extends State<ChooseLocation> {
4152
padding: const EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
4253
child: Card(
4354
child: ListTile(
44-
onTap: () {},
55+
onTap: () {
56+
updateTime(index);
57+
},
4558
title: Text(locations[index].location),
4659
leading: CircleAvatar(
4760
backgroundImage: AssetImage('assets/${locations[index].flag}'),

world_time_app/lib/pages/home.dart

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class _HomeState extends State<Home> {
99

1010
Map data = {};
1111

12-
@override
13-
void initState() {
14-
super.initState();
15-
}
12+
// @override
13+
// void initState() {
14+
// super.initState();
15+
// }
1616

1717
@override
1818
Widget build(BuildContext context) {
1919

20-
data = ModalRoute.of(context).settings.arguments;
20+
data = data.isNotEmpty ? data : ModalRoute.of(context).settings.arguments;
2121

2222
// set background image
2323
String bgImage = data['isDaytime'] ? 'day.png' : 'night.png';
@@ -38,8 +38,18 @@ class _HomeState extends State<Home> {
3838
child: Column(
3939
children: <Widget>[
4040
FlatButton.icon(
41-
onPressed: () {
42-
Navigator.pushNamed(context, '/location');
41+
onPressed: () async {
42+
dynamic result = await Navigator.pushNamed(context, '/location');
43+
if(result != null){
44+
setState(() {
45+
data = {
46+
'time': result['time'],
47+
'location': result['location'],
48+
'isDaytime': result['isDaytime'],
49+
'flag': result['flag']
50+
};
51+
});
52+
}
4353
},
4454
icon: Icon(
4555
Icons.edit_location,

0 commit comments

Comments
 (0)