Skip to content

Commit

Permalink
flags api changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
emreesen27 committed Dec 5, 2020
1 parent ff9fb5b commit d742c7f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 71 deletions.
107 changes: 55 additions & 52 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
TextEditingController textController = new TextEditingController();
SharedPreferences _shared;
List<String> countryList = new List();
String countryName,
countryFlag,
totalConfirmed,
totalDeaths,
totalRecovered,
newConfirmed,
newDeaths,
newRecovered,
updateDate;
List<String> _countryList = new List();
String _countryName,
_countryFlag,
_totalConfirmed,
_totalDeaths,
_totalRecovered,
_newConfirmed,
_newDeaths,
_newRecovered,
_updateDate;

Future _getJsonData() async {
var _response = await http.get("https://api.covid19api.com/summary");
Expand Down Expand Up @@ -80,29 +79,30 @@ class _MyHomePageState extends State<MyHomePage> {
final int countrySize = (snapshot.data['Countries'] as List).length;

for (int i = 0; i < countrySize; i++) {
countryList.add(snapshot.data['Countries'][i]['Country']);
_countryList.add(snapshot.data['Countries'][i]['Country']);
}

for (int i = 0; i < countrySize; i++) {
if (snapshot.data['Countries'][i]['Country'].toString() ==
countryName) {
totalConfirmed =
_countryName) {
_totalConfirmed =
snapshot.data['Countries'][i]['TotalConfirmed'].toString();
totalDeaths =
_totalDeaths =
snapshot.data['Countries'][i]['TotalDeaths'].toString();
totalRecovered =
_totalRecovered =
snapshot.data['Countries'][i]['TotalRecovered'].toString();
newConfirmed =
_newConfirmed =
snapshot.data['Countries'][i]['NewConfirmed'].toString();
newDeaths =
_newDeaths =
snapshot.data['Countries'][i]['NewDeaths'].toString();
newRecovered =
_newRecovered =
snapshot.data['Countries'][i]['NewRecovered'].toString();

countryFlag =
snapshot.data['Countries'][i]['CountryCode'].toString();
_countryFlag = snapshot.data['Countries'][i]['CountryCode']
.toString()
.toLowerCase();

updateDate = snapshot.data['Countries'][i]['Date']
_updateDate = snapshot.data['Countries'][i]['Date']
.toString()
.substring(0, 10);
}
Expand All @@ -126,28 +126,31 @@ class _MyHomePageState extends State<MyHomePage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CachedNetworkImage(
imageUrl:
'https://www.countryflags.io/$countryFlag/shiny/64.png',
imageBuilder: (context, imageProvider) =>
Container(
width: 90,
height: 90,
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.fill,
Padding(
padding: const EdgeInsets.all(10.0),
child: CachedNetworkImage(
imageUrl:
'https://flagcdn.com/56x42/$_countryFlag.png',
imageBuilder: (context, imageProvider) =>
Container(
width: 60,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.fill,
),
),
),
placeholder: (context, url) => Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) =>
Icon(Icons.error),
),
placeholder: (context, url) => Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) =>
Icon(Icons.error),
),
Text(
'$countryName'.toUpperCase(),
'$_countryName'.toUpperCase(),
style: TextStyle(
fontSize: 18,
color: Colors.black87,
Expand All @@ -172,16 +175,16 @@ class _MyHomePageState extends State<MyHomePage> {
children: [
textField(
desc: 'Total Confirmed :',
value: '$totalConfirmed',
value: '$_totalConfirmed',
color: Color(0xff3498db),
),
textField(
desc: 'Total Deaths :',
value: '$totalDeaths',
value: '$_totalDeaths',
color: Color(0xffd72323)),
textField(
desc: 'Total Recovered :',
value: '$totalRecovered',
value: '$_totalRecovered',
color: Color(0xff30e3ca)),
],
),
Expand All @@ -197,17 +200,17 @@ class _MyHomePageState extends State<MyHomePage> {
children: [
textField(
desc: 'New Confirmed :',
value: '$newConfirmed',
value: '$_newConfirmed',
color: Color(0xff3498db),
),
textField(
desc: 'New Deaths :',
value: '$newDeaths',
value: '$_newDeaths',
color: Color(0xffd72323),
),
textField(
desc: 'New Recovered :',
value: '$newRecovered',
value: '$_newRecovered',
color: Color(0xff30e3ca),
),
],
Expand All @@ -228,7 +231,7 @@ class _MyHomePageState extends State<MyHomePage> {
bottom: 3.0,
),
child: Text(
'Last Update : $updateDate',
'Last Update : $_updateDate',
style: TextStyle(color: Colors.black87),
),
),
Expand All @@ -252,12 +255,12 @@ class _MyHomePageState extends State<MyHomePage> {
cancelText: 'Cancel',
confirmText: 'Ok',
title: 'Pick Your Country',
items: countryList,
selectedItem: countryName,
items: _countryList,
selectedItem: _countryName,
onChanged: (value) {
setState(() {
countryName = value;
_setCountry(countryName);
_countryName = value;
_setCountry(_countryName);
});
});
},
Expand All @@ -268,9 +271,9 @@ class _MyHomePageState extends State<MyHomePage> {
_initShared() async {
_shared = await SharedPreferences.getInstance();
if (_shared.getString('countryName') == null)
setState(() => countryName = 'Afghanistan');
setState(() => _countryName = 'Afghanistan');
else
setState(() => countryName = _shared.getString('countryName'));
setState(() => _countryName = _shared.getString('countryName'));
}

_setCountry(String countryName) async {
Expand Down
38 changes: 19 additions & 19 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
cached_network_image:
dependency: "direct dev"
description:
Expand All @@ -42,28 +42,28 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.3"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -91,7 +91,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -204,21 +204,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.1"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -335,7 +335,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
sqflite:
dependency: transitive
description:
Expand All @@ -356,21 +356,21 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
synchronized:
dependency: transitive
description:
Expand All @@ -384,21 +384,21 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.3"
uuid:
dependency: transitive
description:
Expand All @@ -412,7 +412,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.3"
xdg_directories:
dependency: transitive
description:
Expand All @@ -435,5 +435,5 @@ packages:
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"

0 comments on commit d742c7f

Please sign in to comment.