Implemented way to fetch stations in batches

This commit is contained in:
2025-01-27 19:14:58 +01:00
parent 5df67920ea
commit 9e37ebbc22
2 changed files with 38 additions and 3 deletions

View File

@@ -4,13 +4,31 @@ import '../model/flood_station.dart';
import 'api.dart';
class FloodStationProvider extends ChangeNotifier {
List<FloodStation> _allStations = [];
FloodStation? selectedStation;
List<FloodStation> _allStations = [];
List<FloodStation> get allStations => _allStations;
Future loadAllStationsInBatches({silent = false}) {
int offset = 0;
return Future.doWhile(() async {
final stations = await Api.fetchStationsByRange(500, offset);
if (stations.isNotEmpty) {
_allStations.addAll(stations);
if (!silent) {
notifyListeners();
}
offset += 500;
return true;
} else {
return false;
}
});
}
Future loadAllStations({silent = false}) {
return Api.fetchStations().then(
return Api.fetchAllStations().then(
(value) {
_allStations = value;
if (!silent) {