Weight on hedgehog screen
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -30,6 +30,7 @@ class _IgelListState extends ConsumerState<IgelListScreen> {
|
||||
List<Igel> items = [];
|
||||
bool busy = true;
|
||||
String? err;
|
||||
Map<int, Messwert> _latestMesswertByIgel = {};
|
||||
|
||||
// Suche
|
||||
final searchC = TextEditingController();
|
||||
@@ -85,6 +86,7 @@ class _IgelListState extends ConsumerState<IgelListScreen> {
|
||||
items = data;
|
||||
err = null;
|
||||
});
|
||||
await _loadLatestMesswerte(data);
|
||||
} catch (e) {
|
||||
setState(() => err = e.toString());
|
||||
} finally {
|
||||
@@ -92,6 +94,23 @@ class _IgelListState extends ConsumerState<IgelListScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadLatestMesswerte(List<Igel> igelList) async {
|
||||
final latestById = <int, Messwert>{};
|
||||
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<void> _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<IgelListScreen> {
|
||||
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<void> Function(_IgelEditResult updated) onEditAll;
|
||||
final Future<void> 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')),
|
||||
|
||||
Reference in New Issue
Block a user