Skip to content

Commit fc80207

Browse files
committed
lesson-33
1 parent 6120344 commit fc80207

File tree

7 files changed

+75
-41
lines changed

7 files changed

+75
-41
lines changed

world_time_app/assets/day.png

1.17 MB
Loading

world_time_app/assets/night.png

1.4 MB
Loading

world_time_app/lib/pages/home.dart

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,64 @@ class _HomeState extends State<Home> {
1818
Widget build(BuildContext context) {
1919

2020
data = ModalRoute.of(context).settings.arguments;
21-
print(data);
21+
22+
// set background image
23+
String bgImage = data['isDaytime'] ? 'day.png' : 'night.png';
24+
Color bgColor = data['isDaytime'] ? Colors.blue : Colors.indigo[700];
2225

2326
return Scaffold(
24-
//appBar: AppBar(),
27+
backgroundColor: bgColor,
2528
body: SafeArea(
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'],
29+
child: Container(
30+
decoration: BoxDecoration(
31+
image: DecorationImage(
32+
image: AssetImage('assets/$bgImage'),
33+
fit: BoxFit.cover,
34+
)
35+
),
36+
child: Padding(
37+
padding: const EdgeInsets.fromLTRB(0, 120.0, 0, 0),
38+
child: Column(
39+
children: <Widget>[
40+
FlatButton.icon(
41+
onPressed: () {
42+
Navigator.pushNamed(context, '/location');
43+
},
44+
icon: Icon(
45+
Icons.edit_location,
46+
color: Colors.grey[300],
47+
),
48+
label: Text(
49+
'Edit Location',
4550
style: TextStyle(
46-
fontSize: 28.0,
47-
letterSpacing: 2.0,
51+
color: Colors.grey[300],
4852
),
4953
),
50-
],
51-
),
52-
SizedBox(height: 20.0),
53-
Text(
54-
data['time'],
55-
style: TextStyle(
56-
fontSize: 66.0,
57-
)
58-
),
59-
],
54+
),
55+
SizedBox(height: 20.0),
56+
Row(
57+
mainAxisAlignment: MainAxisAlignment.center,
58+
children: <Widget>[
59+
Text(
60+
data['location'],
61+
style: TextStyle(
62+
fontSize: 28.0,
63+
letterSpacing: 2.0,
64+
color: Colors.white,
65+
),
66+
),
67+
],
68+
),
69+
SizedBox(height: 20.0),
70+
Text(
71+
data['time'],
72+
style: TextStyle(
73+
fontSize: 66.0,
74+
color: Colors.white
75+
)
76+
),
77+
],
78+
),
6079
),
6180
),
6281
),

world_time_app/lib/pages/loading.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:world_time_app/services/world_time.dart';
3+
import 'package:flutter_spinkit/flutter_spinkit.dart';
34

45
class Loading extends StatefulWidget {
56
@override
@@ -14,7 +15,8 @@ class _LoadingState extends State<Loading> {
1415
Navigator.pushReplacementNamed(context, '/home', arguments: {
1516
'location': instance.location,
1617
'flag': instance.flag,
17-
'time': instance.time
18+
'time': instance.time,
19+
'isDaytime': instance.isDaytime
1820
});
1921
}
2022

@@ -27,10 +29,13 @@ class _LoadingState extends State<Loading> {
2729
@override
2830
Widget build(BuildContext context) {
2931
return Scaffold(
30-
body: Padding(
31-
padding: const EdgeInsets.all(50.0),
32-
child: Text('loading'),
33-
),
32+
backgroundColor: Colors.blue[900],
33+
body: Center(
34+
child: SpinKitFadingCube(
35+
color: Colors.white,
36+
size: 50.0,
37+
)
38+
)
3439
);
3540
}
3641
}

world_time_app/lib/services/world_time.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class WorldTime {
88
String time; // the time in that location
99
String flag; // url to an asset flag icon
1010
String url; // location url for api endpoint
11+
bool isDaytime; // true or false if daytime or not
1112

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

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

2930
// set the time property
31+
isDaytime = now.hour > 6 && now.hour < 20 ? true : false;
3032
time = DateFormat.jm().format(now);
3133
}
3234
catch (e) {

world_time_app/pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ packages:
4141
description: flutter
4242
source: sdk
4343
version: "0.0.0"
44+
flutter_spinkit:
45+
dependency: "direct main"
46+
description:
47+
name: flutter_spinkit
48+
url: "https://pub.dartlang.org"
49+
source: hosted
50+
version: "3.1.0"
4451
flutter_test:
4552
dependency: "direct dev"
4653
description: flutter
@@ -165,3 +172,4 @@ packages:
165172
version: "2.0.8"
166173
sdks:
167174
dart: ">=2.2.2 <3.0.0"
175+
flutter: ">=0.1.4 <2.0.0"

world_time_app/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies:
2525
cupertino_icons: ^0.1.2
2626
http: ^0.12.0+2
2727
intl: ^0.15.8
28+
flutter_spinkit: "^3.1.0"
2829

2930

3031
dev_dependencies:
@@ -44,9 +45,8 @@ flutter:
4445
uses-material-design: true
4546

4647
# To add assets to your application, add an assets section, like this:
47-
# assets:
48-
# - images/a_dot_burr.jpeg
49-
# - images/a_dot_ham.jpeg
48+
assets:
49+
- assets/
5050

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

0 commit comments

Comments
 (0)