Skip to content

Commit

Permalink
lesson-31
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshaunjp committed Aug 16, 2019
1 parent 82a42b1 commit 6120344
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
56 changes: 42 additions & 14 deletions world_time_app/lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'dart:convert';

class Home extends StatefulWidget {
@override
Expand All @@ -9,27 +7,57 @@ class Home extends StatefulWidget {

class _HomeState extends State<Home> {

Map data = {};

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

@override
Widget build(BuildContext context) {

data = ModalRoute.of(context).settings.arguments;
print(data);

return Scaffold(
//appBar: AppBar(),
body: SafeArea(
child: Column(
children: <Widget>[
FlatButton.icon(
onPressed: () {
Navigator.pushNamed(context, '/location');
},
icon: Icon(Icons.edit_location),
label: Text(
'Edit Location'
)
)
],
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 120.0, 0, 0),
child: Column(
children: <Widget>[
FlatButton.icon(
onPressed: () {
Navigator.pushNamed(context, '/location');
},
icon: Icon(Icons.edit_location),
label: Text(
'Edit Location'
)
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
data['location'],
style: TextStyle(
fontSize: 28.0,
letterSpacing: 2.0,
),
),
],
),
SizedBox(height: 20.0),
Text(
data['time'],
style: TextStyle(
fontSize: 66.0,
)
),
],
),
),
),
);
Expand Down
11 changes: 5 additions & 6 deletions world_time_app/lib/pages/loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ class Loading extends StatefulWidget {

class _LoadingState extends State<Loading> {

String time = 'loading';

void setupWorldTime() async {
WorldTime instance = WorldTime(location: 'Berlin', flag: 'germany.png', url: 'Europe/Berlin');
await instance.getTime();
print(instance.time);
setState(() {
time = instance.time;
Navigator.pushReplacementNamed(context, '/home', arguments: {
'location': instance.location,
'flag': instance.flag,
'time': instance.time
});
}

Expand All @@ -30,7 +29,7 @@ class _LoadingState extends State<Loading> {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(50.0),
child: Text(time),
child: Text('loading'),
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion world_time_app/lib/services/world_time.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:http/http.dart';
import 'dart:convert';
import 'package:intl/intl.dart';

class WorldTime {

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

// set the time property
time = now.toString();
time = DateFormat.jm().format(now);
}
catch (e) {
print(e);
Expand Down
7 changes: 7 additions & 0 deletions world_time_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
intl:
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.8"
matcher:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions world_time_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: ^0.12.0+2
intl: ^0.15.8


dev_dependencies:
Expand Down

0 comments on commit 6120344

Please sign in to comment.