Fixed bug - Loading Indicator now functions correctly
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:async/async.dart';
|
||||
|
||||
import '../model/flood_station.dart';
|
||||
import 'api.dart';
|
||||
|
||||
class FloodStationProvider extends ChangeNotifier {
|
||||
FloodStation? selectedStation;
|
||||
bool filtered = false;
|
||||
|
||||
List<FloodStation> _allStations = [];
|
||||
List<FloodStation> _filteredStations = [];
|
||||
|
||||
List<FloodStation> get allStations => _allStations;
|
||||
List<FloodStation> get filteredStations => _filteredStations;
|
||||
|
||||
CancelableOperation? _filteredStationsFuture;
|
||||
|
||||
CancelableOperation? get filteredStationsFuture => _filteredStationsFuture;
|
||||
|
||||
Future loadAllStationsInBatches({silent = false}) {
|
||||
int offset = 0;
|
||||
@@ -37,4 +45,26 @@ class FloodStationProvider extends ChangeNotifier {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future loadFilteredStations(String filter, {silent = false}) {
|
||||
if (_filteredStationsFuture != null) {
|
||||
_filteredStationsFuture!.cancel();
|
||||
}
|
||||
final future = Api.fetchFilteredStations(filter);
|
||||
_filteredStationsFuture = CancelableOperation.fromFuture(future).then(
|
||||
(value) {
|
||||
_filteredStations = value;
|
||||
if (!silent) {
|
||||
notifyListeners();
|
||||
}
|
||||
},
|
||||
);
|
||||
return future;
|
||||
}
|
||||
|
||||
void cancelFilterLoading() {
|
||||
if (_filteredStationsFuture != null) {
|
||||
_filteredStationsFuture!.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user