fetchStations static method
Implementation
static Future<List<Station>> fetchStations(
String apiKey, {
String? lineCode,
}) async {
final String host = _buildAllStationUrl(
lineCode: lineCode,
);
final response = await http.get(
Uri.parse(host),
headers: {"api_key": apiKey},
);
Map<String, dynamic> responseArr = readJson(response.body);
if (responseArr.isEmpty) return [];
if (responseArr[ApiFields.stations] == null) return [];
if (responseArr[ApiFields.stations] is List) {
return ((responseArr[ApiFields.stations] as List?) ?? [])
.map((station) => Station.fromJson(station))
.toList();
}
return [];
}