Used Provider-Package to encapsulate state management
This commit is contained in:
22
lib/services/flood_station_provider.dart
Normal file
22
lib/services/flood_station_provider.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/flood_station.dart';
|
||||
import 'api.dart';
|
||||
|
||||
class FloodStationProvider extends ChangeNotifier {
|
||||
List<FloodStation> _allStations = [];
|
||||
FloodStation? selectedStation;
|
||||
|
||||
List<FloodStation> get allStations => _allStations;
|
||||
|
||||
Future loadAllStations({silent = false}) {
|
||||
return Api.fetchStations().then(
|
||||
(value) {
|
||||
_allStations = value;
|
||||
if (!silent) {
|
||||
notifyListeners();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user