Professional Documents
Culture Documents
Note: now just through the images you have to understand what’s going on ….
pg. 1
pg. 2
pg. 3
pg. 4
Code test 2: List view builder
As according to our code route, when we ‘click on’ location on home page we will redirect to location screen…but…. there is nothing to see right now!!!!!
So……...
pg. 5
pg. 6
pg. 7
Code test 3: Updating the location instead of only printing it on consol….
pg. 8
pg. 9
pg. 10
FINAL CODE…….All the Best……
main.dart
import 'package:flutter/material.dart';
import 'package:lab10_2_worldtime_api/pages/home.dart';
import 'package:lab10_2_worldtime_api/pages/choose_location.dart';
import 'package:lab10_2_worldtime_api/pages/loading.dart';
/*
void main() => runApp(MaterialApp(
// home: Home(),
routes: {
'/': (context) => Loading(),
'/home': (context) => Home(),
'/location': (context) => ChooseLocation(),
}
));
pubspec.yaml
name: lab10_2_worldtime_api
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
pg. 11
# In Android, build-name is used as versionName while build-number used as
versionCode.
# Read more about Android versioning at
https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as
CFBundleVersion.
# Read more about iOS versioning at
#
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistK
eyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.17.5 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
http: ^0.13.5
intl: ^0.17.0
flutter_spinkit: ^5.1.0
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
pg. 12
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
services-world_time.dart(word_time.dart---in my code)
import 'package:http/http.dart';
import 'dart:convert';
import 'package:intl/intl.dart';
class WordTime {
try {
// Make Request for time and receive response
home.dart
import 'package:flutter/material.dart';
@override
State<Home> createState() => _HomeState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: appBgColor,
body: SafeArea(
child:Container (
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/$bgImage'),
fit: BoxFit.cover,
)
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0.0,120.0,0.0,0.0),
child: Column(
children: [
pg. 14
TextButton.icon(
onPressed: () async {
dynamic result = await Navigator.pushNamed(context,'/location');
setState((){
data = {
'time': result['time'],
'location': result['location'],
'isDayTime': result['isDayTime'],
'flag': result['flag'],
};
});
},
icon: Icon(
Icons.edit_location,
color: Colors.grey[300],
),
label: Text(
'EDIT LOCATION',
style: TextStyle(
color: Colors.grey[300],
fontWeight: FontWeight.w300,
fontSize: 20,
),
),
),
SizedBox(height: 24.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
data['location'],
style: TextStyle(
letterSpacing: 2.0,
fontSize: 36.0,
fontWeight: FontWeight.w500,
color: Colors.white70,
),
)
],
),
SizedBox(height: 24.0,),
Text(
data['time'],
style: TextStyle(
fontSize: 70.0,
color: Colors.white70,
),
)
],
),
),
)
),
);
}
}
pg. 15
loading.dart
import 'package:flutter/material.dart';
import 'package:lab10_2_worldtime_api/services/word_time.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
WordTime timeinstance =
WordTime(location: 'kolkata',flag: 'india.png',url: 'Asia/Kolkata');
await timeinstance.getTime();
Navigator.pushReplacementNamed(context, '/home',arguments: {
'location' : timeinstance.location,
'flag' : timeinstance.flag,
'time' : timeinstance.time,
'isDayTime' : timeinstance.isDayTime,
});
@override
void initState() {
super.initState();
setWorldTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurpleAccent,
body: Center(
child: SpinKitFadingCube(
color: Colors.white,
size: 90.0,
),
)
);
}
}
pg. 16
choose_location.dart
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:lab10_2_worldtime_api/services/word_time.dart';
@override
State<ChooseLocation> createState() => _ChooseLocationState();
}
int counter = 0;
List<WordTime> locations = [
WordTime(location: 'kolkata',flag: 'india.png',url: 'Asia/Kolkata'),
WordTime(location: 'Manila',flag: 'philippines.png',url: 'Asia/Manila'),
WordTime(location: 'Singapore',flag: 'singapore.png',url: 'Asia/Singapore'),
WordTime(location: 'Brisbane',flag: 'australia.png',url: 'Australia/Brisbane'),
WordTime(location: 'Madrid',flag: 'spain.png',url: 'Europe/Madrid'),
WordTime(location: 'Vienna',flag: 'austria.png',url: 'Europe/Vienna'),
WordTime(location: 'Maldives',flag: 'maldives.png',url: 'Indian/Maldives'),
WordTime(location: 'Johannesburg',flag: 'south-africa.png',url:
'Africa/Johannesburg'),
WordTime(location: 'Barbados',flag: 'barbados.png',url: 'America/Barbados'),
WordTime(location: 'Costa_Rica',flag: 'costa-rica.png',url:
'America/Costa_Rica'),
WordTime(location: 'Jamaica',flag: 'jamaica.png',url: 'America/Jamaica'),
WordTime(location: 'Phoenix',flag: 'usa.png',url: 'America/Phoenix'),
WordTime(location: 'Broken_Hill',flag: 'australia.png',url:
'Australia/Broken_Hill'),
WordTime(location: 'Moscow',flag: 'russia.png',url: 'Europe/Moscow'),
];
Navigator.pop(context,{
'location' : instance.location,
'flag' : instance.flag,
'time' : instance.time,
'isDayTime' : instance.isDayTime,
});
}
@override
Widget build(BuildContext context) {
// print('BUILD FUNCTION RUN IN CHOOSE LOCATION...');
return Scaffold(
backgroundColor: Colors.blueGrey[200],
// when we come/route from different screen IN APPBAR FLUTTER WILL DEFAULTLY
pg. 17
// PLACED "BACK ARROW <- .....
appBar: AppBar(
backgroundColor: Colors.deepPurpleAccent,
title: Text('CHOOSE LOCATION'),
centerTitle: true,
elevation: 0,
),
/*
body: ElevatedButton(
onPressed: () {
setState(() {
counter += 1;
});
},
);
}
}
pg. 18