getRoutes method

Future<Map<String, ShuttleRoute>> getRoutes ()

Getter method to retrieve the list of routes

Implementation

Future<Map<String, ShuttleRoute>> getRoutes() async {
/// Returns a map that contains the bus id and its routes.
///
/// Fetch 'routes' data from the JSON API and store in varaible 'response'.
/// If unable to retreive data, repsonse is set to null
/// New map is created to hold the shuttle id's and values.
/// Create a map instance where the keys and its values are computed
/// using a hashmap. Decode the data.
/// Using json, the key is assigned by getting the 'name'
/// and the value is assigned to the routes of the shuttle
///
///
///     return routeMap;
  var response = await fetch('routes');
  Map<String, ShuttleRoute> routeMap = response != null
      ? Map.fromIterable(
          (json.decode(response.body) as List)
              .where((json) => json['enabled']),
          key: (json) => json['name'],
          value: (json) => ShuttleRoute.fromJson(json))
      : {};
  // routeList.removeWhere((route) => route == null);
  return routeMap;
}