diff --git a/lib/src/models/comparison_of_accumulated_cases.dart b/lib/src/models/comparison_of_accumulated_cases.dart index e8ff62a..dd8c2bf 100644 --- a/lib/src/models/comparison_of_accumulated_cases.dart +++ b/lib/src/models/comparison_of_accumulated_cases.dart @@ -7,7 +7,7 @@ part 'comparison_of_accumulated_cases.g.dart'; @JsonSerializable() class ComparisonOfAccumulatedCases { - @JsonKey(name: 'countries_info') + @JsonKey(name: 'data') Map countries; @JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson) diff --git a/lib/src/models/comparison_of_accumulated_cases.g.dart b/lib/src/models/comparison_of_accumulated_cases.g.dart index 8de2c72..f8246d6 100644 --- a/lib/src/models/comparison_of_accumulated_cases.g.dart +++ b/lib/src/models/comparison_of_accumulated_cases.g.dart @@ -9,7 +9,7 @@ part of 'comparison_of_accumulated_cases.dart'; ComparisonOfAccumulatedCases _$ComparisonOfAccumulatedCasesFromJson( Map json) { return ComparisonOfAccumulatedCases() - ..countries = (json['countries_info'] as Map)?.map( + ..countries = (json['data'] as Map)?.map( (k, e) => MapEntry( k, e == null @@ -23,6 +23,6 @@ ComparisonOfAccumulatedCases _$ComparisonOfAccumulatedCasesFromJson( Map _$ComparisonOfAccumulatedCasesToJson( ComparisonOfAccumulatedCases instance) => { - 'countries_info': instance.countries, + 'data': instance.countries, 'updated': dateTimeToJson(instance.updated), }; diff --git a/lib/src/models/comparison_of_accumulated_cases_item.dart b/lib/src/models/comparison_of_accumulated_cases_item.dart index 349b3fb..ced42ab 100644 --- a/lib/src/models/comparison_of_accumulated_cases_item.dart +++ b/lib/src/models/comparison_of_accumulated_cases_item.dart @@ -10,6 +10,7 @@ class ComparisonOfAccumulatedCasesItem { List daily; List active; List stringency; + String name; ComparisonOfAccumulatedCasesItem(); diff --git a/lib/src/models/comparison_of_accumulated_cases_item.g.dart b/lib/src/models/comparison_of_accumulated_cases_item.g.dart index 9f934b1..87c1d24 100644 --- a/lib/src/models/comparison_of_accumulated_cases_item.g.dart +++ b/lib/src/models/comparison_of_accumulated_cases_item.g.dart @@ -16,7 +16,8 @@ ComparisonOfAccumulatedCasesItem _$ComparisonOfAccumulatedCasesItemFromJson( ..active = (json['active'] as List)?.map((e) => e as int)?.toList() ..stringency = (json['stringency'] as List) ?.map((e) => (e as num)?.toDouble()) - ?.toList(); + ?.toList() + ..name = json['name'] as String; } Map _$ComparisonOfAccumulatedCasesItemToJson( @@ -28,4 +29,5 @@ Map _$ComparisonOfAccumulatedCasesItemToJson( 'daily': instance.daily, 'active': instance.active, 'stringency': instance.stringency, + 'name': instance.name, }; diff --git a/lib/src/models/data_model.dart b/lib/src/models/data_model.dart index 57d0fa0..c1e6044 100644 --- a/lib/src/models/data_model.dart +++ b/lib/src/models/data_model.dart @@ -24,459 +24,6 @@ class DataModel { return provinces[abbr].municipalities[code]; } - static String prettyCountry(String country) { - var dict = { - 'Vietnam': 'Vietnam', - 'Austria': 'Austria', - 'Cambodia': 'Camboya', - 'Kazakhstan': 'Kazajstán', - "Cote d'Ivoire": 'Costa de Marfil', - 'Spain': 'España', - 'Serbia': 'Serbia', - 'Ethiopia': 'Etiopía', - 'Brazil': 'Brasil', - 'Pakistan': 'Pakistán', - 'Panama': 'Panamá', - 'Syria': 'Siria', - 'France': 'Francia', - 'Germany': 'Alemania', - 'Montenegro': 'Montenegro', - 'Switzerland': 'Suiza', - 'Paraguay': 'Paraguay', - 'Holy See': 'Santa Sede', - 'Nepal': 'Nepal', - 'Norway': 'Noruega', - 'Afghanistan': 'Afganistán', - 'Djibouti': 'Yitubi', - 'Ireland': 'Irlanda', - 'United Arab Emirates': 'Emiratos Árabes Unidos', - 'Israel': 'Israel', - 'Bulgaria': 'Bulgaria', - 'Korea, South': 'Corea del Sur', - 'Cyprus': 'Chipre', - 'Peru': 'Perú', - 'Azerbaijan': 'Azerbaiyán', - 'Philippines': 'Filipinas', - 'Bahamas': 'Bahamas', - 'India': 'India', - //'MS Zaandam': 'MS Zaandam', - 'Canada': 'Canadá', - 'Rwanda': 'Ruanda', - 'Cuba': 'Cuba', - 'Thailand': 'Tailandia', - 'Brunei': 'Brunéi', - 'El Salvador': 'El Salvador', - 'North Macedonia': 'Macedonia del Norte', - 'Saint Vincent and the Grenadines': 'San Vicente y las Granadinas', - 'Jamaica': 'Jamaica', - 'Greece': 'Grecia', - 'Bolivia': 'Bolivia', - 'Dominica': 'Dominica', - 'Togo': 'Togo', - 'Mauritius': 'Mauricio', - 'Russia': 'Rusia', - 'Lebanon': 'Líbano', - 'Zimbabwe': 'Zimbabue', - 'Nigeria': 'Nigeria', - 'Finland': 'Finlandia', - 'Burma': 'Birmania', - 'Iraq': 'Irak', - 'United Kingdom': 'Reino Unido', - 'Tanzania': 'Tanzania', - 'Uruguay': 'Uruguay', - 'South Africa': 'Sudáfrica', - 'Somalia': 'Somalia', - 'Algeria': 'Argelia', - 'Benin': 'Benín', - 'Niger': 'Níger', - 'West Bank and Gaza': 'Cisjordania', - 'Uganda': 'Uganda', - 'San Marino': 'San Marino', - 'Liberia': 'Liberia', - 'Iran': 'Irán', - 'Mexico': 'México', - 'Honduras': 'Honduras', - 'Burkina Faso': 'Burkina Faso', - 'Australia': 'Australia', - 'Chile': 'Chile', - 'Haiti': 'Haití', - 'Turkey': 'Turquía', - 'Madagascar': 'Madagascar', - 'Saint Lucia': 'Santa Lucía', - 'Papua New Guinea': 'Papúa Nueva Guinea', - 'Central African Republic': 'República Centroafricana', - 'Eritrea': 'Eritrea', - 'Lithuania': 'Lituania', - 'Kyrgyzstan': 'Kirguistán', - 'Andorra': 'Andorra', - 'Laos': 'Laos', - 'Mali': 'Mali', - 'Guinea': 'Guinea', - 'Luxembourg': 'Luxemburgo', - 'Gambia': 'Gambia', - 'Mongolia': 'Mongolia', - 'Costa Rica': 'Costa Rica', - 'Trinidad and Tobago': 'Trinidad y Tobago', - 'Mauritania': 'Mauritania', - 'Antigua and Barbuda': 'Antigua y Barbuda', - 'Libya': 'Libia', - 'Zambia': 'Zambia', - 'Timor-Leste': 'Timor-Leste', - 'Guyana': 'Guayana', - 'Tunisia': 'Túnez', - 'Japan': 'Japón', - 'Liechtenstein': 'Liechtenstein', - 'Saint Kitts and Nevis': 'San Cristóbal y Nieves', - 'Senegal': 'Senegal', - 'Hungary': 'Hungría', - 'Moldova': 'Moldavia', - 'Qatar': 'Katar', - 'US': 'Estados Unidos', - 'Belarus': 'Bielorrusia', - 'Chad': 'Chad', - 'Malaysia': 'Malasia', - 'Romania': 'Rumania', - 'Argentina': 'Argentina', - 'Belize': 'Belice', - 'Angola': 'Angola', - 'Sweden': 'Suecia', - 'China': 'China', - 'Jordan': 'Jordán', - 'Italy': 'Italia', - 'Latvia': 'Letonia', - 'Seychelles': 'Seychelles', - 'Ghana': 'Ghana', - 'Colombia': 'Colombia', - 'Albania': 'Albania', - 'Saudi Arabia': 'Arabia Saudita', - 'Estonia': 'Estonia', - 'Monaco': 'Mónaco', - 'Ukraine': 'Ucrania', - 'Uzbekistan': 'Uzbekistán', - 'Maldives': 'Maldivas', - 'Morocco': 'Marruecos', - 'Portugal': 'Portugal', - 'Kenya': 'Kenia', - 'Guatemala': 'Guatemala', - 'Gabon': 'Gabón', - 'Belgium': 'Bélgica', - 'Iceland': 'Islandia', - 'Cabo Verde': 'Cabo Verde', - 'Mozambique': 'Mozambique', - 'Indonesia': 'Indonesia', - 'Egypt': 'Egipto', - 'Taiwan*': 'Taiwán *', - 'Netherlands': 'Países Bajos', - 'Slovakia': 'Eslovaquia', - 'Bosnia and Herzegovina': 'Bosnia y Herzegovina', - 'Cameroon': 'Camerún', - 'Venezuela': 'Venezuela', - 'Kuwait': 'Kuwait', - 'Malta': 'Malta', - 'Nicaragua': 'Nicaragua', - 'Congo (Kinshasa)': 'Congo (Kinshasa)', - 'Singapore': 'Singapur', - 'Bhutan': 'Bután', - 'Bangladesh': 'Bangladesh', - 'Ecuador': 'Ecuador', - 'Georgia': 'Georgia', - 'Namibia': 'Namibia', - 'Denmark': 'Dinamarca', - 'Poland': 'Polonia', - 'Suriname': 'Surinam', - 'Slovenia': 'Eslovenia', - 'Congo (Brazzaville)': 'Congo (Brazzaville)', - 'Guinea-Bissau': 'Guinea-Bissau', - 'Dominican Republic': 'República Dominicana', - //'Diamond Princess': 'Princesa del Diamante', - 'Grenada': 'Granada', - 'Barbados': 'Barbados', - 'New Zealand': 'Nueva Zelanda', - 'Eswatini': 'Eswatini', - 'Czechia': 'Chequia', - 'Kosovo': 'Kosovo', - 'Sudan': 'Sudán', - 'Armenia': 'Armenia', - 'Bahrain': 'Bahrein', - 'Sri Lanka': 'Sri Lanka', - 'Equatorial Guinea': 'Guinea Ecuatorial', - 'Croatia': 'Croacia', - 'Oman': 'Omán', - 'Fiji': 'Fiyi', - }; - return dict.containsKey(country) ? dict[country] : country; - } - - static Map countries() { - var dict = { - "AD": "Andorra", - "AE": "United Arab Emirates", - "AF": "Afghanistan", - "AG": "Antigua and Barbuda", - // "AI": "Anguilla", - "AL": "Albania", - "AM": "Armenia", - // "AN": "Netherlands Antilles", - "AO": "Angola", - // "AQ": "Antarctica", - "AR": "Argentina", - // "AS": "American Samoa", - "AT": "Austria", - "AU": "Australia", - // "AW": "Aruba", - // "AX": "\u00c5land Islands", - "AZ": "Azerbaijan", - "BA": "Bosnia and Herzegovina", - "BB": "Barbados", - "BD": "Bangladesh", - "BE": "Belgium", - "BF": "Burkina Faso", - "BG": "Bulgaria", - "BH": "Bahrain", - // "BI": "Burundi", - "BJ": "Benin", - // "BL": "Saint Barthélemy", - // "BM": "Bermuda", - "BN": "Brunéi", //"Brunei Darussalam", - "BO": "Bolivia", //"Bolivia, Plurinational State of", - // "BQ": "Caribbean Netherlands", - "BR": "Brazil", - "BS": "Bahamas", - "BT": "Bhutan", - // "BV": "Bouvet Island", - // "BW": "Botswana", - "BY": "Belarus", - "BZ": "Belize", - "CA": "Canada", - "UX": "Camboya", - // "CC": "Cocos (Keeling) Islands", - "CD": "Congo (Kinshasa)", //"Congo, the Democratic Republic of the", - "CF": "Central African Republic", - "CG": "Congo (Brazzaville)", //"Congo", - "CH": "Switzerland", - "CI": "Cote d'Ivoire", - // "CK": "Cook Islands", - "CL": "Chile", - "CM": "Cameroon", - "CN": "China", - "CO": "Colombia", - "CR": "Costa Rica", - // "CU": "Cuba", - "CV": "Cabo Verde", //"Cape Verde", - // "CW": "Cura\u00e7ao", - // "CX": "Christmas Island", - "CY": "Cyprus", - "CZ": "Czechia", //"Czech Republic", - "DE": "Germany", - "DJ": "Djibouti", - "DK": "Denmark", - "DM": "Dominica", - "DO": "Dominican Republic", - "DZ": "Algeria", - "EC": "Ecuador", - "EE": "Estonia", - "EG": "Egypt", - // "EH": "Western Sahara", - "ER": "Eritrea", - "ES": "Spain", - "ET": "Ethiopia", - // "EU": "Europe", - "FI": "Finland", - "FJ": "Fiji", - // "FK": "Falkland Islands (Malvinas)", - // "FM": "Micronesia, Federated States of", - // "FO": "Faroe Islands", - "FR": "France", - "GA": "Gabon", - // "GB-ENG": "England", - "GB-NIR": "Ireland", - // "GB-SCT": "Scotland", - // "GB-WLS": "Wales", - "GB": "United Kingdom", - "GD": "Grenada", - "GE": "Georgia", - // "GF": "French Guiana", - // "GG": "Guernsey", - "GH": "Ghana", - // "GI": "Gibraltar", - // "GL": "Greenland", - "GM": "Gambia", - "GN": "Guinea", - // "GP": "Guadeloupe", - "GQ": "Equatorial Guinea", - "GR": "Greece", - // "GS": "South Georgia and the South Sandwich Islands", - "GT": "Guatemala", - // "GU": "Guam", - "GW": "Guinea-Bissau", - "GY": "Guyana", - // "HK": "Hong Kong", - // "HM": "Heard Island and McDonald Islands", - "HN": "Honduras", - "HR": "Croatia", - "HT": "Haiti", - "HU": "Hungary", - "ID": "Indonesia", - // "IE": "Ireland", - "IL": "Israel", - // "IM": "Isle of Man", - "IN": "India", - // "IO": "British Indian Ocean Territory", - "IQ": "Iraq", - "IR": "Irán", //"Iran, Islamic Republic of", - "IS": "Iceland", - "IT": "Italy", - // "JE": "Jersey", - "JM": "Jamaica", - "JO": "Jordan", - "JP": "Japan", - "KE": "Kenya", - "KG": "Kyrgyzstan", - // "KH": "Cambodia", - // "KI": "Kiribati", - // "KM": "Comoros", - "KN": "Saint Kitts and Nevis", - // "KP": "Korea, Democratic People's Republic of", - "KR": "Korea, South", //"Korea, Republic of", - "KW": "Kuwait", - // "KY": "Cayman Islands", - "KZ": "Kazakhstan", - "LA": "Laos", //"Lao People's Democratic Republic", - "LB": "Lebanon", - "LC": "Saint Lucia", - "LI": "Liechtenstein", - "LK": "Sri Lanka", - "LR": "Liberia", - // "LS": "Lesotho", - "LT": "Lithuania", - "LU": "Luxembourg", - "LV": "Latvia", - "LY": "Libya", - "MA": "Morocco", - "MC": "Monaco", - "MD": "Moldova", //"Moldova, Republic of", - "ME": "Montenegro", - // "MF": "Saint Martin", - "MG": "Madagascar", - // "MH": "Marshall Islands", - "MK": "North Macedonia", //"Macedonia, the former Yugoslav Republic of", - "ML": "Mali", - "MM": "Burma", //"Myanmar", - "MN": "Mongolia", - // "MO": "Macao", - // "MP": "Northern Mariana Islands", - // "MQ": "Martinique", - "MR": "Mauritania", - // "MS": "Montserrat", - "MT": "Malta", - "MU": "Mauritius", - "MV": "Maldives", - // "MW": "Malawi", - "MX": "Mexico", - "MY": "Malaysia", - "MZ": "Mozambique", - "NA": "Namibia", - // "NC": "New Caledonia", - "NE": "Niger", - // "NF": "Norfolk Island", - "NG": "Nigeria", - "NI": "Nicaragua", - "NL": "Netherlands", - "NO": "Norway", - "NP": "Nepal", - // "NR": "Nauru", - // "NU": "Niue", - "NZ": "New Zealand", - "OM": "Oman", - "PA": "Panama", - "PE": "Peru", - // "PF": "French Polynesia", - "PG": "Papua New Guinea", - "PH": "Philippines", - "PK": "Pakistan", - "PL": "Poland", - // "PM": "Saint Pierre and Miquelon", - // "PN": "Pitcairn", - // "PR": "Puerto Rico", - "PS": "West Bank and Gaza", //"Palestine", - "PT": "Portugal", - // "PW": "Palau", - "PY": "Paraguay", - "QA": "Qatar", - // "RE": "Réunion", - "RO": "Romania", - "RS": "Serbia", - "RU": "Russia", - "RW": "Rwanda", - "SA": "Saudi Arabia", - // "SB": "Solomon Islands", - "SC": "Seychelles", - "SD": "Sudan", - "SE": "Sweden", - "SG": "Singapore", - // "SH": "Saint Helena, Ascension and Tristan da Cunha", - "SI": "Slovenia", - // "SJ": "Svalbard and Jan Mayen Islands", - "SK": "Slovakia", - // "SL": "Sierra Leone", - "SM": "San Marino", - "SN": "Senegal", - "SO": "Somalia", - "SR": "Suriname", - // "SS": "South Sudan", - // "ST": "Sao Tome and Principe", - "SV": "El Salvador", - // "SX": "Sint Maarten (Dutch part)", - "SY": "Syria", - "SZ": "Eswatini", //"Swaziland", - // "TC": "Turks and Caicos Islands", - "TD": "Chad", - // "TF": "French Southern Territories", - "TG": "Togo", - "TH": "Thailand", - // "TJ": "Tajikistan", - // "TK": "Tokelau", - "TL": "Timor-Leste", - // "TM": "Turkmenistan", - "TN": "Tunisia", - // "TO": "Tonga", - "TR": "Turkey", - "TT": "Trinidad and Tobago", - // "TV": "Tuvalu", - "TW": "Taiwan", - "TZ": "Tanzania", //"Tanzania, United Republic of", - "UA": "Ukraine", - "UG": "Uganda", - // "UM": "US Minor Outlying Islands", - "US": "US", //"United States", - "UY": "Uruguay", - "UZ": "Uzbekistan", - "VA": "Holy See", - "VC": "Saint Vincent and the Grenadines", - "VE": "Venezuela", //"Venezuela, Bolivarian Republic of", - // "VG": "Virgin Islands, British", - // "VI": "Virgin Islands, U.S.", - "VN": "Viet Nam", - // "VU": "Vanuatu", - // "WF": "Wallis and Futuna Islands", - "XK": "Kosovo", - // "WS": "Samoa", - // "YE": "Yemen", - // "YT": "Mayotte", - "ZA": "South Africa", - "ZM": "Zambia", - "ZW": "Zimbabwe" - }; - return dict; - } - - static String countryCode(String country) { - var dict = countries(); - var countryCode = - dict.keys.firstWhere((k) => dict[k] == country, orElse: () => null); - return countryCode; - } - factory DataModel.fromJson(Map json) => _$DataModelFromJson(json); diff --git a/lib/src/pages/settings_page.dart b/lib/src/pages/settings_page.dart index 3645305..2314437 100644 --- a/lib/src/pages/settings_page.dart +++ b/lib/src/pages/settings_page.dart @@ -1,4 +1,7 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:getflutter/getflutter.dart'; import 'package:preferences/preferences.dart'; import 'package:covid19cuba/src/utils/utils.dart'; @@ -65,6 +68,51 @@ class SettingsPageState extends State { 'ahorrar y a la vez tener una estabilidad del servicio buena.', isDefault: true, ), + Container( + margin: EdgeInsets.symmetric(horizontal: 30, vertical: 30), + child: GFButton( + text: 'Reiniciar estado de la Aplicación', + textColor: Colors.black, + textStyle: TextStyle( + color: Colors.black, + ), + color: Constants.primaryColor, + shape: GFButtonShape.pills, + type: GFButtonType.outline2x, + borderSide: BorderSide(width: 1.0, color: Colors.black), + fullWidthButton: true, + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + // return object of type Dialog + return AlertDialog( + title: Text('Confirme'), + content: Text('Usted esta seguro o segura que desea ' + 'reiniciar el estado de la aplicación.\n\n' + 'Esto hará que vuelva al estado de acabada de ' + 'instalar.'), + actions: [ + FlatButton( + child: Text('Si'), + onPressed: () { + PrefService.clear(); + exit(0); + }, + ), + FlatButton( + child: Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + ), + ), ]), ); } diff --git a/lib/src/pages/update_page.dart b/lib/src/pages/update_page.dart index c91c58c..68ff265 100644 --- a/lib/src/pages/update_page.dart +++ b/lib/src/pages/update_page.dart @@ -122,7 +122,12 @@ class UpdatePageState extends State { ), TouchableUrlImage( Constants.apklisBanner, - Constants.apklisUrl, + () async { + var packageInfo = await PackageInfo.fromPlatform(); + var apklisUrl = + 'https://archive.apklis.cu/application/apk/club.postdata.covid19cuba-v${packageInfo.buildNumber}.apk'; + getUrl(apklisUrl); + }, leftMargin: 50, rightMargin: 50, topMargin: 5, @@ -146,7 +151,12 @@ class UpdatePageState extends State { ), TouchableUrlImage( Constants.githubBanner, - Constants.githubUrl, + () async { + var packageInfo = await PackageInfo.fromPlatform(); + var gitHubUrl = + 'https://github.com/covid19cuba/covid19cuba-app/releases/download/v${packageInfo.version}/app.apk'; + getUrl(gitHubUrl); + }, leftMargin: 50, rightMargin: 50, topMargin: 5, diff --git a/lib/src/utils/constants.dart b/lib/src/utils/constants.dart index e781865..ba1078e 100644 --- a/lib/src/utils/constants.dart +++ b/lib/src/utils/constants.dart @@ -9,8 +9,8 @@ class Constants { static const int notificationMinutesRange = 1440; static const int setUpTasksMinutesDefault = 15; - static const String defaultCompareCountry = 'Hungary'; - static const String countryCuba = 'Cuba'; + static const String defaultCompareCountry = 'HUN'; + static const String countryCuba = 'CUB'; static const showMunicipalities = "covidData"; static const showProvinces = "covidData2"; @@ -789,10 +789,9 @@ class Constants { ], [ 'Yudivián Almeida', - 'Lic. Ciencia de la Computación, graduado de la Univ. de La Habana ' - 'de Ciencias Matemáticas. Profesor de la Fac. Matemática y ' - 'Computación de la Univ. de La Habana. Editor de Datos de ' - 'Postdata.club.', + 'Lic. Ciencia de la Computación, Dr. Ciencias Matemáticas, Profesor de ' + 'la Fac. Matemática y Computación de la Univ. de La Habana, Editor ' + 'de Datos de Postdata.club', '', ], [ @@ -836,10 +835,10 @@ class Constants { 'http://covidcuba.swlx.info', 'https://www.swlx.info', ], - [ + /*[ 'Joven Club', 'http://covid19.jovenclub.cu', 'https://www.jovenclub.cu', - ] + ],*/ ]; } diff --git a/lib/src/widgets/comparison_widget.dart b/lib/src/widgets/comparison_widget.dart index 32e144a..4b2377d 100644 --- a/lib/src/widgets/comparison_widget.dart +++ b/lib/src/widgets/comparison_widget.dart @@ -2,8 +2,10 @@ import 'dart:math'; import 'dart:developer' as dev; import 'package:charts_flutter/flutter.dart' as charts; +import 'package:country_pickers/countries.dart'; import 'package:country_pickers/country.dart'; import 'package:country_pickers/country_pickers.dart'; +import 'package:covid19cuba/src/widgets/widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:preferences/preferences.dart'; @@ -26,8 +28,6 @@ class ComparisonWidget extends StatefulWidget { class ComparisonWidgetState extends State { String selectedCountry = Constants.defaultCompareCountry; String selectedOption = 'Confirmados'; - Country _selectedDialogCountry = CountryPickerUtils.getCountryByIsoCode( - DataModel.countryCode(Constants.defaultCompareCountry)); final List options = List() ..add('Confirmados') @@ -41,23 +41,15 @@ class ComparisonWidgetState extends State { ComparisonWidgetState({this.comparisonOfAccumulatedCases}) { assert(comparisonOfAccumulatedCases != null); - if (getCountriesList().indexOf(selectedCountry) == -1) { + selectedCountry = PrefService.getString(Constants.prefCompareCountry) ?? + Constants.defaultCompareCountry; + if (!comparisonOfAccumulatedCases.countries.keys + .contains(selectedCountry)) { selectedCountry = Constants.defaultCompareCountry; - _selectedDialogCountry = CountryPickerUtils.getCountryByIsoCode( - DataModel.countryCode(selectedCountry)); PrefService.setString(Constants.prefCompareCountry, selectedCountry); } } - List getCountriesList() { - var list = comparisonOfAccumulatedCases.countries.keys - .where((c) => c != Constants.countryCuba) - .toList(); - list.sort((a, b) => - DataModel.prettyCountry(a).compareTo(DataModel.prettyCountry(b))); - return list; - } - List> getSelectionModels() { return [ charts.SelectionModelConfig( @@ -71,21 +63,46 @@ class ComparisonWidgetState extends State { ]; } + String getChartTitle() { + switch (selectedOption) { + case 'Confirmados': + case 'Activos': + case 'Diarios': + case 'Recuperados': + case 'Fallecidos': + return 'Casos'; + case 'Stringency Index': + return 'Valor del índice'; + } + return ''; + } + String getLegend() { - String legend; switch (selectedOption) { case 'Confirmados': case 'Activos': case 'Diarios': case 'Recuperados': case 'Fallecidos': - legend = 'Casos'; - break; + return 'Casos'; case 'Stringency Index': - legend = 'Valor del índice'; - break; + return ''; } - return legend; + return ''; + } + + String getMeasure(num measure) { + switch (selectedOption) { + case 'Confirmados': + case 'Activos': + case 'Diarios': + case 'Recuperados': + case 'Fallecidos': + return measure.toInt().toString(); + case 'Stringency Index': + return measure.toString(); + } + return ''; } List getBehaviors() { @@ -97,7 +114,7 @@ class ComparisonWidgetState extends State { titleOutsideJustification: charts.OutsideJustification.middleDrawArea, ), charts.ChartTitle( - getLegend(), + getChartTitle(), behaviorPosition: charts.BehaviorPosition.start, titleStyleSpec: charts.TextStyleSpec(fontSize: 11), titleOutsideJustification: charts.OutsideJustification.middleDrawArea, @@ -108,7 +125,7 @@ class ComparisonWidgetState extends State { showMeasures: true, measureFormatter: (num measure) { if (measure == null) return ''; - return measure.toInt().toString() + ' Casos'; + return '${getMeasure(measure)} ${getLegend()}'; }, ), charts.LinePointHighlighter( @@ -290,7 +307,6 @@ class ComparisonWidgetState extends State { .countries[selectedCountry].stringency.length; break; } - log(length); return length != 0; } @@ -337,14 +353,14 @@ class ComparisonWidgetState extends State { } return [ charts.Series( - id: DataModel.prettyCountry(selectedCountry), + id: comparisonOfAccumulatedCases.countries[selectedCountry].name, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, domainFn: (_, i) => i, measureFn: (item, _) => item, data: listForeign, ), charts.Series( - id: Constants.countryCuba, + id: comparisonOfAccumulatedCases.countries[Constants.countryCuba].name, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, domainFn: (_, i) => i, measureFn: (item, _) => item, @@ -396,7 +412,7 @@ class ComparisonWidgetState extends State { } return [ charts.Series( - id: DataModel.prettyCountry(selectedCountry), + id: comparisonOfAccumulatedCases.countries[selectedCountry].name, colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, domainFn: (_, i) => i, measureFn: (item, _) => item, @@ -407,7 +423,7 @@ class ComparisonWidgetState extends State { .toList(), ), charts.Series( - id: Constants.countryCuba, + id: comparisonOfAccumulatedCases.countries[Constants.countryCuba].name, colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault, domainFn: (_, i) => i, measureFn: (item, _) => item, @@ -416,17 +432,27 @@ class ComparisonWidgetState extends State { ]; } - Widget _buildSelectedCountry(Country country) => Column( + static Country getCountryByIso3Code(String iso3Code) { + try { + return countryList.firstWhere( + (country) => country.iso3Code.toLowerCase() == iso3Code.toLowerCase(), + ); + } catch (error) { + throw Exception('The initialValue provided is not a supported iso code!'); + } + } + + Widget _buildSelectedCountry(String iso3code) => Column( children: [ Row( children: [ - CountryPickerUtils.getDefaultFlagImage(country), + CountryPickerUtils.getDefaultFlagImage( + getCountryByIso3Code(iso3code), + ), SizedBox(width: 8.0), Expanded( child: Text( - DataModel.prettyCountry( - DataModel.countries()[country.isoCode], - ), + comparisonOfAccumulatedCases.countries[iso3code].name, ), ), Icon(Icons.arrow_downward), @@ -445,9 +471,7 @@ class ComparisonWidgetState extends State { SizedBox(width: 8.0), Flexible( child: Text( - DataModel.prettyCountry( - DataModel.countries()[country.isoCode], - ), + comparisonOfAccumulatedCases.countries[country.iso3Code].name, ), ), // SizedBox(width: 8.0), @@ -457,41 +481,53 @@ class ComparisonWidgetState extends State { void _openCountryPickerDialog() => showDialog( context: context, builder: (context) => Theme( - data: Theme.of(context).copyWith(primaryColor: Colors.pink), - child: CountryPickerDialog( - titlePadding: EdgeInsets.all(8.0), - semanticLabel: 'País seleccionado ' + selectedCountry, - searchCursorColor: Colors.pinkAccent, - searchInputDecoration: InputDecoration(hintText: 'Buscar...'), - searchEmptyView: Center(child: Text('No se encontró el país')), - isSearchable: false, - title: Text('Seleccione el país'), - onValuePicked: (Country country) { - PrefService.setString(Constants.prefCompareCountry, - DataModel.countries()[country.isoCode]); - setState(() { - selectedCountry = DataModel.countries()[country.isoCode]; - _selectedDialogCountry = country; - }); - }, - itemFilter: (c) => - DataModel.countries().keys.contains(c.isoCode), - itemBuilder: _buildDialogItem)), + data: Theme.of(context).copyWith(primaryColor: Colors.pink), + child: PlusCountryPickerDialog( + titlePadding: EdgeInsets.all(8.0), + semanticLabel: 'País seleccionado ' + + comparisonOfAccumulatedCases.countries[selectedCountry].name, + searchCursorColor: Colors.pinkAccent, + searchInputDecoration: InputDecoration(hintText: 'Buscar...'), + searchEmptyView: Center(child: Text('No se encontró el país')), + isSearchable: true, + title: Text('Seleccione el país'), + onValuePicked: (Country country) { + PrefService.setString( + Constants.prefCompareCountry, + country.iso3Code, + ); + setState(() { + selectedCountry = country.iso3Code; + }); + }, + itemFilter: (c) => comparisonOfAccumulatedCases.countries.keys + .contains(c.iso3Code), + itemBuilder: _buildDialogItem, + sortComparator: (a, b) => comparisonOfAccumulatedCases + .countries[a.iso3Code].name + .compareTo( + comparisonOfAccumulatedCases.countries[b.iso3Code].name), + searchFunction: (Country country, String value) { + return comparisonOfAccumulatedCases + .countries[country.iso3Code].name + .toLowerCase() + .startsWith(value.toLowerCase()); + }, + ), + ), ); @override Widget build(BuildContext context) { selectedCountry = PrefService.getString(Constants.prefCompareCountry) ?? Constants.defaultCompareCountry; - _selectedDialogCountry = CountryPickerUtils.getCountryByIsoCode( - DataModel.countryCode(selectedCountry)); return Column( children: [ Container( margin: EdgeInsets.only(left: 20, right: 20, top: 20), child: Center( child: Text( - 'Comparación de ${Constants.countryCuba}', + 'Comparación de Cuba', textAlign: TextAlign.center, style: TextStyle( color: Constants.primaryColor, @@ -519,37 +555,9 @@ class ComparisonWidgetState extends State { margin: EdgeInsets.only(left: 35, right: 35), child: ListTile( onTap: _openCountryPickerDialog, - title: _buildSelectedCountry(_selectedDialogCountry), + title: _buildSelectedCountry(selectedCountry), ), ), - /*Container( - margin: EdgeInsets.only(left: 50, right: 50), - child: DropdownButton( - value: selectedCountry, - icon: Icon(Icons.arrow_downward), - iconSize: 24, - isExpanded: true, - elevation: 16, - style: TextStyle(color: Constants.primaryColor), - underline: Container( - height: 2, - color: Constants.primaryColor, - ), - onChanged: (String newValue) { - PrefService.setString(Constants.prefCompareCountry, newValue); - setState(() { - selectedCountry = newValue; - }); - }, - items: getCountriesList() - .map>((String value) { - return DropdownMenuItem( - value: value, - child: Text(DataModel.prettyCountry(value)), - ); - }).toList(), - ), - ),*/ Container( margin: EdgeInsets.only(left: 20, right: 20, top: 10), child: Center( diff --git a/lib/src/widgets/curves_evolution.dart b/lib/src/widgets/curves_evolution.dart index ed34aaf..aa65500 100644 --- a/lib/src/widgets/curves_evolution.dart +++ b/lib/src/widgets/curves_evolution.dart @@ -8,7 +8,6 @@ import 'package:random_color/random_color.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:covid19cuba/src/utils/utils.dart'; -import 'package:covid19cuba/src/models/models.dart'; class CurvesEvolutionWidget extends StatefulWidget { final Map curvesEvolution; @@ -91,7 +90,7 @@ class CurvesEvolutionWidgetState extends State { curvesEvolution.entries.map((item) { var localIndex = index++; return charts.Series( - id: DataModel.prettyCountry(item.key), + id: item.key, colorFn: (_, __) => colors[localIndex], domainFn: (_, i) => item.value['cummulative_sum'][i], measureFn: (item, _) => item, diff --git a/lib/src/widgets/plus_country_picker_dialog.dart b/lib/src/widgets/plus_country_picker_dialog.dart new file mode 100644 index 0000000..dd41a6f --- /dev/null +++ b/lib/src/widgets/plus_country_picker_dialog.dart @@ -0,0 +1,229 @@ +import 'package:country_pickers/countries.dart'; +import 'package:country_pickers/country.dart'; +import 'package:country_pickers/utils/typedefs.dart'; + +import 'package:country_pickers/utils/my_alert_dialog.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; + +///Provides a customizable [Dialog] which displays all countries +/// with optional search feature + +class PlusCountryPickerDialog extends StatefulWidget { + /// Callback that is called with selected Country + final ValueChanged onValuePicked; + + /// The (optional) title of the dialog is displayed in a large font at the top + /// of the dialog. + /// + /// Typically a [Text] widget. + final Widget title; + + /// Padding around the title. + /// + /// If there is no title, no padding will be provided. Otherwise, this padding + /// is used. + /// + /// This property defaults to providing 12 pixels on the top, + /// 16 pixels on bottom of the title. If the [content] is not null, then no bottom padding is + /// provided (but see [contentPadding]). If it _is_ null, then an extra 20 + /// pixels of bottom padding is added to separate the [title] from the + /// [actions]. + final EdgeInsetsGeometry titlePadding; + + /// Padding around the content. + + final EdgeInsetsGeometry contentPadding; + + /// The semantic label of the dialog used by accessibility frameworks to + /// announce screen transitions when the dialog is opened and closed. + /// + /// If this label is not provided, a semantic label will be infered from the + /// [title] if it is not null. If there is no title, the label will be taken + /// from [MaterialLocalizations.alertDialogLabel]. + /// + /// See also: + /// + /// * [SemanticsConfiguration.isRouteName], for a description of how this + /// value is used. + final String semanticLabel; + + /// Filters the available country list + final ItemFilter itemFilter; + + /// [Comparator] to be used in sort of country list + final Comparator sortComparator; + + /// List of countries that are placed on top + final List priorityList; + + ///Callback that is called with selected item of type Country which returns a + ///Widget to build list view item inside dialog + final ItemBuilder itemBuilder; + + /// The (optional) horizontal separator used between title, content and + /// actions. + /// + /// If this divider is not provided a [Divider] is used with [height] + /// property is set to 0.0 + final Widget divider; + + /// The [divider] is not displayed if set to false. Default is set to false. + final bool isDividerEnabled; + + /// Determines if search [TextField] is shown or not + /// Defaults to false + final bool isSearchable; + + /// The optional [decoration] of search [TextField] + final InputDecoration searchInputDecoration; + + ///The optional [cursorColor] of search [TextField] + final Color searchCursorColor; + + ///The search empty view is displayed if nothing returns from search result + final Widget searchEmptyView; + + ///By default the dialog will be popped of the navigator on selection of a value. + ///Set popOnPick to false to prevent this behaviour. + final bool popOnPick; + + ///Custom search function + final Function searchFunction; + + PlusCountryPickerDialog({ + Key key, + this.onValuePicked, + this.title, + this.titlePadding, + this.contentPadding = const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 16.0), + this.semanticLabel, + this.itemFilter, + this.sortComparator, + this.priorityList, + this.itemBuilder, + this.isDividerEnabled = false, + this.divider = const Divider( + height: 0.0, + ), + this.isSearchable = false, + this.popOnPick = true, + this.searchInputDecoration, + this.searchCursorColor, + this.searchEmptyView, + this.searchFunction, + }) : super(key: key); + + @override + PlusSingleChoiceDialogState createState() { + return new PlusSingleChoiceDialogState(); + } +} + +class PlusSingleChoiceDialogState extends State { + List _allCountries; + + List _filteredCountries; + + @override + void initState() { + _allCountries = + countryList.where(widget.itemFilter ?? acceptAllCountries).toList(); + + if (widget.sortComparator != null) { + _allCountries.sort(widget.sortComparator); + } + + if (widget.priorityList != null) { + widget.priorityList.forEach((Country country) => _allCountries + .removeWhere((Country c) => country.isoCode == c.isoCode)); + _allCountries.insertAll(0, widget.priorityList); + } + + _filteredCountries = _allCountries; + + super.initState(); + } + + @override + Widget build(BuildContext context) { + return MyAlertDialog( + title: _buildHeader(), + contentPadding: widget.contentPadding, + semanticLabel: widget.semanticLabel, + content: _buildContent(context), + isDividerEnabled: widget.isDividerEnabled, + divider: widget.divider, + ); + } + + _buildContent(BuildContext context) { + return _filteredCountries.isNotEmpty + ? ListView( + shrinkWrap: true, + children: _filteredCountries + .map((item) => SimpleDialogOption( + child: widget.itemBuilder != null + ? widget.itemBuilder(item) + : Text(item.name), + onPressed: () { + widget.onValuePicked(item); + if (widget.popOnPick) { + Navigator.pop(context); + } + }, + )) + .toList(), + ) + : widget.searchEmptyView ?? + Center( + child: Text('No country found.'), + ); + } + + _buildHeader() { + return widget.isSearchable + ? Column( + children: [ + _buildTitle(), + _buildSearchField(), + ], + ) + : _buildTitle(); + } + + _buildTitle() { + return widget.titlePadding != null + ? Padding( + padding: widget.titlePadding, + child: widget.title, + ) + : widget.title; + } + + _buildSearchField() { + return TextField( + cursorColor: widget.searchCursorColor, + decoration: + widget.searchInputDecoration ?? InputDecoration(hintText: 'Search'), + onChanged: (String value) { + setState(() { + _filteredCountries = _allCountries + .where((Country country) => widget.searchFunction == null + ? country.name + .toLowerCase() + .startsWith(value.toLowerCase()) || + country.phoneCode.startsWith(value) || + country.isoCode + .toLowerCase() + .startsWith(value.toLowerCase()) || + country.iso3Code + .toLowerCase() + .startsWith(value.toLowerCase()) + : widget.searchFunction(country, value)) + .toList(); + }); + }, + ); + } +} diff --git a/lib/src/widgets/top_20_accumulated_countries_widget.dart b/lib/src/widgets/top_20_accumulated_countries_widget.dart index 9012afa..4f40243 100644 --- a/lib/src/widgets/top_20_accumulated_countries_widget.dart +++ b/lib/src/widgets/top_20_accumulated_countries_widget.dart @@ -160,7 +160,7 @@ class Top20CountriesWidget extends StatelessWidget { alignment: Alignment.centerLeft, margin: EdgeInsets.all(5), child: Text( - '${DataModel.prettyCountry(item.name)}', + item.name, style: TextStyle( color: Constants.primaryColor, fontWeight: FontWeight.normal, diff --git a/lib/src/widgets/touchable_url_widget.dart b/lib/src/widgets/touchable_url_widget.dart index f9c5bd2..de05418 100644 --- a/lib/src/widgets/touchable_url_widget.dart +++ b/lib/src/widgets/touchable_url_widget.dart @@ -4,7 +4,7 @@ import 'package:covid19cuba/src/utils/utils.dart'; class TouchableUrlImage extends StatelessWidget { const TouchableUrlImage( this.asset, - this.url, { + this.onTap, { this.leftMargin: 0, this.rightMargin: 0, this.topMargin: 0, @@ -12,7 +12,7 @@ class TouchableUrlImage extends StatelessWidget { }); final String asset; - final String url; + final GestureTapCallback onTap; final double leftMargin; final double rightMargin; final double topMargin; @@ -31,7 +31,7 @@ class TouchableUrlImage extends StatelessWidget { ), child: GestureDetector( child: Image.asset(asset), - onTap: () => getUrl(url), + onTap: onTap, ), ); } diff --git a/lib/src/widgets/widgets.dart b/lib/src/widgets/widgets.dart index 0c406a5..a783355 100644 --- a/lib/src/widgets/widgets.dart +++ b/lib/src/widgets/widgets.dart @@ -18,6 +18,7 @@ export 'pie_cases_nationality.dart'; export 'pie_contagion_widget.dart'; export 'pie_sex_widget.dart'; export 'pie_tests_percent_widget.dart'; +export 'plus_country_picker_dialog.dart'; export 'presentation_widget.dart'; export 'province_map_widget.dart'; export 'province_widget.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 6dc339f..00381a1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: covid19cuba description: Mobile application of Covid19 Cuba Data project implemented with Flutter. -version: 0.6.0+9 +version: 0.6.1+10 environment: sdk: ">=2.6.0 <3.0.0"