diff --git a/lib/main.dart b/lib/main.dart index 5b85d44..6af3ff3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -33,18 +33,17 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - TextEditingController textController = new TextEditingController(); SharedPreferences _shared; - List countryList = new List(); - String countryName, - countryFlag, - totalConfirmed, - totalDeaths, - totalRecovered, - newConfirmed, - newDeaths, - newRecovered, - updateDate; + List _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"); @@ -80,29 +79,30 @@ class _MyHomePageState extends State { 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); } @@ -126,28 +126,31 @@ class _MyHomePageState extends State { 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, @@ -172,16 +175,16 @@ class _MyHomePageState extends State { 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)), ], ), @@ -197,17 +200,17 @@ class _MyHomePageState extends State { 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), ), ], @@ -228,7 +231,7 @@ class _MyHomePageState extends State { bottom: 3.0, ), child: Text( - 'Last Update : $updateDate', + 'Last Update : $_updateDate', style: TextStyle(color: Colors.black87), ), ), @@ -252,12 +255,12 @@ class _MyHomePageState extends State { 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); }); }); }, @@ -268,9 +271,9 @@ class _MyHomePageState extends State { _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 { diff --git a/pubspec.lock b/pubspec.lock index 63f8ca8..b89dc51 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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"