fetchVehicleEstimations function Null safety

Future<List<VehicleEstimation>> fetchVehicleEstimations(
  1. String cityName,
  2. String stopCode
)

Implementation

Future<List<VehicleEstimation>> fetchVehicleEstimations(
    String cityName, String stopCode) async {
  final response = await http.get(
      Uri.parse('$apiBaseUrl/$cityName/$apiVersion/stop/$stopCode/estimation'));

  if (response.statusCode == 200) {
    List<dynamic> json = jsonDecode(response.body);
    List<VehicleEstimation> vehicleEstimations = [];

    for (final vehicleEstimation in json) {
      vehicleEstimations.add(VehicleEstimation.fromJson(vehicleEstimation));
    }

    return vehicleEstimations;
  } else {
    throw Exception('Failed to load stop arrivals estimations.');
  }
}