Skip to content

Commit

Permalink
lesson-35
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshaunjp committed Aug 16, 2019
1 parent 79b7b67 commit 697020b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
15 changes: 14 additions & 1 deletion world_time_app/lib/pages/choose_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ class _ChooseLocationState extends State<ChooseLocation> {
WorldTime(url: 'Asia/Jakarta', location: 'Jakarta', flag: 'indonesia.png'),
];

void updateTime(index) async {
WorldTime instance = locations[index];
await instance.getTime();
Navigator.pop(context, {
'location': instance.location,
'time': instance.time,
'flag': instance.flag,
'isDaytime': instance.isDaytime,
});
}

@override
void initState() {
super.initState();
Expand All @@ -41,7 +52,9 @@ class _ChooseLocationState extends State<ChooseLocation> {
padding: const EdgeInsets.symmetric(vertical: 1.0, horizontal: 4.0),
child: Card(
child: ListTile(
onTap: () {},
onTap: () {
updateTime(index);
},
title: Text(locations[index].location),
leading: CircleAvatar(
backgroundImage: AssetImage('assets/${locations[index].flag}'),
Expand Down
24 changes: 17 additions & 7 deletions world_time_app/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class _HomeState extends State<Home> {

Map data = {};

@override
void initState() {
super.initState();
}
// @override
// void initState() {
// super.initState();
// }

@override
Widget build(BuildContext context) {

data = ModalRoute.of(context).settings.arguments;
data = data.isNotEmpty ? data : ModalRoute.of(context).settings.arguments;

// set background image
String bgImage = data['isDaytime'] ? 'day.png' : 'night.png';
Expand All @@ -38,8 +38,18 @@ class _HomeState extends State<Home> {
child: Column(
children: <Widget>[
FlatButton.icon(
onPressed: () {
Navigator.pushNamed(context, '/location');
onPressed: () async {
dynamic result = await Navigator.pushNamed(context, '/location');
if(result != null){
setState(() {
data = {
'time': result['time'],
'location': result['location'],
'isDaytime': result['isDaytime'],
'flag': result['flag']
};
});
}
},
icon: Icon(
Icons.edit_location,
Expand Down

2 comments on commit 697020b

@MToheed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I follow the whole flutter beginner series and I am very happy now.

@bruhnugget-nice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the world time app, i get an error: The argument type 'String' can't be assigned to type 'Uri'.

Please sign in to comment.