getByCountry method

Future<List> getByCountry (
  1. {@required String country,
  2. String status,
  3. bool live: false,
  4. String from,
  5. String to}
)

Implementation

Future<List> getByCountry(
    {@required String country,
    String status,
    bool live = false,
    String from,
    String to}) async {
  var res = await _dio.get(
      '/country/$country' +
          (status != null
              ? live
                  ? '/status/$status/live'
                  : '/status/$status'
              : ''),
      queryParameters: {'from': from, 'to': to});

  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;
}