fetchSchedule static method

Future<Schedule> fetchSchedule(
  1. String apiKey, {
  2. required String routeId,
  3. String? date,
  4. bool? includingVariations,
})

Implementation

static Future<Schedule> fetchSchedule(
  String apiKey, {
  required String routeId,
  String? date,
  bool? includingVariations,
}) async {
  final String host = _buildUrl(
    routeId: routeId,
    date: date,
    includingVariations: includingVariations,
  );

  final response = await http.get(
    Uri.parse(host),
    headers: {"api_key": apiKey},
  );

  Map<String, dynamic> responseArr = readJson(response.body);

  if (responseArr.isEmpty) return const Schedule.empty();

  return Schedule.fromJson(responseArr);
}