getEtas method

Future<List<ShuttleEta>> getEtas ()

Getter method to retrieve the list of shuttle eta (estimated times of arrival)

Implementation

Future<List<ShuttleEta>> getEtas() async {
/// Returns a list of shuttle eta (estimated times of arriaval).
///
/// Fetch 'eta' data from JSON API and store in variable 'response'
/// If unable to retreive data, response is set equal to null.
/// Create empty list 'etas'
/// Store data in a map.
/// Decode the in the map and trasfer contents in to etas list
///
///
///     return etas;
  var response = await fetch('eta');
  List<ShuttleEta> etas = [];
  Map<String, dynamic> etamap = response != null
      ? (json.decode(response.body) as Map<String, dynamic>)
      : [];
  etamap.forEach((key, value) {
    etas.add(ShuttleEta.fromJson(value));
  });
  return etas;
}