Used Provider-Package to encapsulate state management

This commit is contained in:
2025-01-27 16:10:28 +01:00
parent c75d905dd8
commit 81f5924df5
7 changed files with 86 additions and 29 deletions

View 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();
}
},
);
}
}