getDayOneTotal method

Future<List> getDayOneTotal (
  1. {@required String country,
  2. String status}
)

Fetches countries information since the day one.

If the status is set, the method returns a list of Covid19CountryEx Otherwise it returns a list of Covid19CountryAllStatus.

The status can be: 'confirmed', 'recovered' or 'deaths'.

Implementation

Future<List> getDayOneTotal({@required String country, String status}) async {
  var res = await _dio.get('/total/dayone/country/$country' +
      (status != null ? '/status/$status' : ''));
  var data = res.data;
  List list = List();

  if (status != null) {
    for (var i in data) {
      list.add(
        Covid19CountryEx(
          country: i['Country'],
          countryCode: i['CountryCode'],
          province: i['Province'],
          city: i['City'],
          cityCode: i['CityCode'],
          lat: i['Lat'],
          lon: i['Lon'],
          cases: i['Cases'],
          status: i['Status'],
          date: i['Date'],
        ),
      );
    }
    return list;
  }

  for (var i in data) {
    list.add(
      Covid19CountryAllStatus(
        country: i['Country'],
        countryCode: i['CountryCode'],
        province: i['Province'],
        city: i['City'],
        cityCode: i['CityCode'],
        lat: i['Lat'],
        lon: i['Lon'],
        confirmed: i['Confirmed'],
        deaths: i['Deaths'],
        recovered: i['Recovered'],
        active: i['Active'],
        date: i['Date'],
      ),
    );
  }
  return list;
}