21 lines
586 B
Dart
21 lines
586 B
Dart
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
|
|
import '../model/flood_station.dart';
|
|
|
|
class Api {
|
|
static const String _rootUrl =
|
|
'https://environment.data.gov.uk/flood-monitoring';
|
|
|
|
static Future<void> fetchStations() async {
|
|
List<FloodStation> stations = [];
|
|
final response = await http.get(Uri.parse('$_rootUrl/id/stations'));
|
|
if (response.statusCode == 200) {
|
|
final Map<String, dynamic> jsonStr = jsonDecode(response.body);
|
|
for (final str in jsonStr['items']) {
|
|
stations.add(FloodStation.fromMap(str));
|
|
}
|
|
}
|
|
}
|
|
}
|