leafittome/lib/features/locations/presentation/locations_screen.dart
cschlaefke f0b420b656 V3: Stellplatz-Bewertung (Standort-Analyse per Foto + Eignungs-Sterne auf Abruf)
Letzter Roadmap-Punkt von V3. Foto-basierte Lichtverhältnis-Analyse pro
Stellplatz (Cloud Function analyzeLocation) und darauf aufbauende, rein
textbasierte Eignungs-Bewertung einer Pflanze (assessPlantFit) — beides
ausschließlich auf Abruf, nicht automatisch (Kostenkontrolle, eigener
Anthropic-Key). Neue Stellplatz-Detailseite, Verlinkung im Pflanzen-Detail,
Erkennung veralteter Bewertungen bei Umzug/Neuanalyse.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 00:17:18 +02:00

106 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/router/app_router.dart';
import '../../../core/widgets/app_drawer.dart';
import '../../../l10n/generated/app_localizations.dart';
import '../../household/data/household_providers.dart';
import '../../household/domain/household.dart';
import '../../plants/data/plants_provider.dart';
import '../data/locations_provider.dart';
class LocationsScreen extends ConsumerWidget {
const LocationsScreen({super.key});
Future<void> _addLocation(BuildContext context, WidgetRef ref) async {
final l10n = AppLocalizations.of(context);
final controller = TextEditingController();
final name = await showDialog<String>(
context: context,
builder: (dialogContext) => AlertDialog(
title: Text(l10n.addLocation),
content: TextField(
controller: controller,
autofocus: true,
decoration: InputDecoration(
labelText: l10n.locationNameLabel,
border: const OutlineInputBorder(),
),
onSubmitted: (value) => Navigator.pop(dialogContext, value),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: Text(l10n.cancel),
),
FilledButton(
onPressed: () => Navigator.pop(dialogContext, controller.text),
child: Text(l10n.save),
),
],
),
);
if (name != null && name.trim().isNotEmpty) {
ref.read(locationRepositoryProvider).addLocation(name.trim());
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
final locationsAsync = ref.watch(locationsProvider);
final locations = locationsAsync.value ?? const [];
final plants = ref.watch(plantsProvider).value ?? const [];
final Widget body;
if (locationsAsync.isLoading && !locationsAsync.hasValue) {
body = const Center(child: CircularProgressIndicator());
} else if (locations.isEmpty) {
body = Center(
child: Text(
l10n.locationsEmpty,
style: Theme.of(context).textTheme.bodyLarge,
),
);
} else {
body = ListView.separated(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 96),
itemCount: locations.length,
separatorBuilder: (_, _) => const Divider(height: 1),
itemBuilder: (context, index) {
final location = locations[index];
final plantCount = plants
.where((plant) => plant.locationId == location.id)
.length;
return ListTile(
leading: const Icon(Icons.place),
title: Text(
location.name,
style: Theme.of(context).textTheme.titleMedium,
),
subtitle: Text(l10n.locationPlantCount(plantCount)),
trailing: const Icon(Icons.chevron_right),
onTap: () =>
context.push(AppRoutes.locationDetail(location.id)),
);
},
);
}
final canEdit = ref.watch(myRoleProvider) == HouseholdRole.member;
return Scaffold(
appBar: AppBar(title: Text(l10n.locationsTitle)),
drawer: const AppDrawer(),
floatingActionButton: canEdit
? FloatingActionButton.extended(
onPressed: () => _addLocation(context, ref),
icon: const Icon(Icons.add),
label: Text(l10n.addLocation),
)
: null,
body: body,
);
}
}