From 3ca5df30501cb252c5eafe361a32b246e771d8d5 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Mon, 2 Feb 2026 14:55:14 +0100 Subject: [PATCH] Weight on hedgehog screen --- .../igel/presentation/igel_detail_screen.dart | 2 +- .../igel/presentation/igel_list_screen.dart | 53 ++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/lib/features/igel/presentation/igel_detail_screen.dart b/lib/features/igel/presentation/igel_detail_screen.dart index ccc2bce..63de672 100644 --- a/lib/features/igel/presentation/igel_detail_screen.dart +++ b/lib/features/igel/presentation/igel_detail_screen.dart @@ -1923,7 +1923,7 @@ class _WeightChartPainter extends CustomPainter { paddingLeft, paddingTop, size.width - paddingLeft - paddingRight, - size.height - paddingTop - paddingBottom, + size.height*2 - paddingTop - paddingBottom, ); final axisPaint = Paint() diff --git a/lib/features/igel/presentation/igel_list_screen.dart b/lib/features/igel/presentation/igel_list_screen.dart index 3b80c92..df21427 100644 --- a/lib/features/igel/presentation/igel_list_screen.dart +++ b/lib/features/igel/presentation/igel_list_screen.dart @@ -30,6 +30,7 @@ class _IgelListState extends ConsumerState { List items = []; bool busy = true; String? err; + Map _latestMesswertByIgel = {}; // Suche final searchC = TextEditingController(); @@ -85,6 +86,7 @@ class _IgelListState extends ConsumerState { items = data; err = null; }); + await _loadLatestMesswerte(data); } catch (e) { setState(() => err = e.toString()); } finally { @@ -92,6 +94,23 @@ class _IgelListState extends ConsumerState { } } + Future _loadLatestMesswerte(List igelList) async { + final latestById = {}; + await Future.wait(igelList.map((ig) async { + try { + final list = await messRepo.list(ig.id); + if (list.isEmpty) return; + final latest = list.reduce( + (a, b) => a.datum.isAfter(b.datum) ? a : b); + latestById[ig.id] = latest; + } catch (_) { + // Messwerte optional: bei Fehler einfach weglassen. + } + })); + if (!mounted) return; + setState(() => _latestMesswertByIgel = latestById); + } + Future _createInline() async { final name = nameC.text.trim(); final note = noteC.text.trim().isEmpty ? null : noteC.text.trim(); @@ -517,9 +536,14 @@ class _IgelListState extends ConsumerState { separatorBuilder: (_, __) => const Divider(height: 1), itemBuilder: (_, i) { final x = visible[i]; + final latest = _latestMesswertByIgel[x.id]; + final weightLabel = latest == null + ? null + : 'Gewicht: ${latest.gewicht} g ยท ${df.format(latest.datum.toLocal())}'; return _IgelTile( key: ValueKey('igel-${x.id}'), igel: x, + weightLabel: weightLabel, onTap: () => context.go('/igel/${x.id}'), // Detailseite onEditAll: (result) async { @@ -580,12 +604,14 @@ class _IgelTile extends StatelessWidget { const _IgelTile({ super.key, required this.igel, + required this.weightLabel, required this.onTap, required this.onEditAll, required this.onDelete, }); final Igel igel; + final String? weightLabel; final VoidCallback onTap; final Future Function(_IgelEditResult updated) onEditAll; final Future Function() onDelete; @@ -626,6 +652,25 @@ class _IgelTile extends StatelessWidget { .textTheme .titleMedium ?.copyWith(fontWeight: FontWeight.w600); + final subtitle = (feature != null || weightLabel != null) + ? Padding( + padding: const EdgeInsets.only(top: 2), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (feature != null) + Text(feature, + style: Theme.of(context).textTheme.bodyMedium), + if (weightLabel != null) + Text(weightLabel!, + style: Theme.of(context) + .textTheme + .bodySmall + ?.copyWith(color: Colors.black54)), + ], + ), + ) + : null; return ListTile( onTap: onTap, @@ -640,13 +685,7 @@ class _IgelTile extends StatelessWidget { Expanded(child: Text(igel.name, style: titleStyle)), ], ), - subtitle: feature != null - ? Padding( - padding: const EdgeInsets.only(top: 2), - child: - Text(feature, style: Theme.of(context).textTheme.bodyMedium), - ) - : null, + subtitle: subtitle, trailing: PopupMenuButton( itemBuilder: (_) => const [ PopupMenuItem(value: 'edit', child: Text('Bearbeiten')),