Skip to content

Commit

Permalink
lesson-33
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshaunjp committed Aug 16, 2019
1 parent 6120344 commit fc80207
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 41 deletions.
Binary file added world_time_app/assets/day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added world_time_app/assets/night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 52 additions & 33 deletions world_time_app/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,64 @@ class _HomeState extends State<Home> {
Widget build(BuildContext context) {

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

// set background image
String bgImage = data['isDaytime'] ? 'day.png' : 'night.png';
Color bgColor = data['isDaytime'] ? Colors.blue : Colors.indigo[700];

return Scaffold(
//appBar: AppBar(),
backgroundColor: bgColor,
body: SafeArea(
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'],
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/$bgImage'),
fit: BoxFit.cover,
)
),
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,
color: Colors.grey[300],
),
label: Text(
'Edit Location',
style: TextStyle(
fontSize: 28.0,
letterSpacing: 2.0,
color: Colors.grey[300],
),
),
],
),
SizedBox(height: 20.0),
Text(
data['time'],
style: TextStyle(
fontSize: 66.0,
)
),
],
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
data['location'],
style: TextStyle(
fontSize: 28.0,
letterSpacing: 2.0,
color: Colors.white,
),
),
],
),
SizedBox(height: 20.0),
Text(
data['time'],
style: TextStyle(
fontSize: 66.0,
color: Colors.white
)
),
],
),
),
),
),
Expand Down
15 changes: 10 additions & 5 deletions world_time_app/lib/pages/loading.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:world_time_app/services/world_time.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class Loading extends StatefulWidget {
@override
Expand All @@ -14,7 +15,8 @@ class _LoadingState extends State<Loading> {
Navigator.pushReplacementNamed(context, '/home', arguments: {
'location': instance.location,
'flag': instance.flag,
'time': instance.time
'time': instance.time,
'isDaytime': instance.isDaytime
});
}

Expand All @@ -27,10 +29,13 @@ class _LoadingState extends State<Loading> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(50.0),
child: Text('loading'),
),
backgroundColor: Colors.blue[900],
body: Center(
child: SpinKitFadingCube(
color: Colors.white,
size: 50.0,
)
)
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions world_time_app/lib/services/world_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class WorldTime {
String time; // the time in that location
String flag; // url to an asset flag icon
String url; // location url for api endpoint
bool isDaytime; // true or false if daytime or not

WorldTime({ this.location, this.flag, this.url });

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

// set the time property
isDaytime = now.hour > 6 && now.hour < 20 ? true : false;
time = DateFormat.jm().format(now);
}
catch (e) {
Expand Down
8 changes: 8 additions & 0 deletions world_time_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_spinkit:
dependency: "direct main"
description:
name: flutter_spinkit
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -165,3 +172,4 @@ packages:
version: "2.0.8"
sdks:
dart: ">=2.2.2 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
6 changes: 3 additions & 3 deletions world_time_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
cupertino_icons: ^0.1.2
http: ^0.12.0+2
intl: ^0.15.8
flutter_spinkit: "^3.1.0"


dev_dependencies:
Expand All @@ -44,9 +45,8 @@ flutter:
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
Expand Down

0 comments on commit fc80207

Please sign in to comment.