41 lines
911 B
Dart
41 lines
911 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../model/flood_station.dart';
|
|
import 'api.dart';
|
|
|
|
class FloodStationProvider extends ChangeNotifier {
|
|
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.fetchAllStations().then(
|
|
(value) {
|
|
_allStations = value;
|
|
if (!silent) {
|
|
notifyListeners();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|