leafittome/lib/features/locations/data/locations_provider.dart
cschlaefke 6e22d9c3aa Projekt-Gerüst: Flutter-App mit Heute-Checkliste, Pflanzenverwaltung, Stellplätzen und Einstellungen
- Flutter/Dart (iOS + Android), Riverpod, go_router, i18n via ARB (deutsch)
- Feature-Struktur: today, plants, locations, household (V2-Platzhalter), settings
- Intervall-Modell: Aufgaben werden aus lastWatered/lastFertilized + Intervall berechnet
- In-Memory-Demo-Daten, Firebase-Anbindung folgt im nächsten Block
- Doku: Architektur, Firebase-Einrichtung, Forgejo-Git-Hosting

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 21:13:18 +02:00

34 lines
1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../domain/plant_location.dart';
/// In-Memory-Stellplätze mit Demo-Daten wird später durch Firestore ersetzt.
class LocationsNotifier extends Notifier<List<PlantLocation>> {
@override
List<PlantLocation> build() {
return const [
PlantLocation(id: 'loc-wohnzimmer', name: 'Wohnzimmer'),
PlantLocation(id: 'loc-schlafzimmer', name: 'Schlafzimmer'),
PlantLocation(id: 'loc-kueche', name: 'Küche'),
];
}
void addLocation(String name) {
final id = 'loc-${DateTime.now().millisecondsSinceEpoch}';
state = [...state, PlantLocation(id: id, name: name)];
}
}
final locationsProvider =
NotifierProvider<LocationsNotifier, List<PlantLocation>>(
LocationsNotifier.new);
final locationByIdProvider =
Provider.family<PlantLocation?, String?>((ref, id) {
if (id == null) return null;
final locations = ref.watch(locationsProvider);
for (final location in locations) {
if (location.id == id) return location;
}
return null;
});