tane/apps/app_seeds/lib/ui/plantares_screen.dart
vjrj adf396d49d feat(plantare): surface product link + dates; spec the bilateral record
The Plantaré screen stored madeOn/dueBy/varietyId but showed none of them,
so it felt half-built. Surface what's already there (no schema change):

- watchPlantareViews() joins each commitment with its variety label
- tile shows the made-on date, a "Return by {date}" line (amber + "overdue"
  when an open promise is past due, via new seedWarning colour), the variety
  name, and taps through to /variety/:id
- add sheet gains an optional return-by date picker (createPlantare already
  took dueBy)
- variety detail shows a read-only commitments section (hidden when empty,
  no add button — honours the single hand-over door)
- i18n en/es/pt/ast; tests for the join, dueBy round-trip, tile, and section

Also specs the deferred two-sided record in docs/design/plantare-bilateral.md
(Nostr pubkey counterparty, PlantareTransport propose->accept->counter-sign,
deferred key/signature/movement columns, provenance DAG, reputation anchor),
with a faithful transcription of the paper Plantaré v0.4 (BAH-Semillero 2009,
CC-BY-SA). Cross-linked from data-model §2.7 and sharing-model §6.
2026-07-13 18:06:33 +02:00

199 lines
6.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../data/variety_repository.dart';
import '../db/enums.dart';
import '../i18n/strings.g.dart';
import 'plantare_sheet.dart';
import 'theme.dart';
/// The Plantares screen — your reproduction commitments (data-model §2.7).
/// Lists what's open (still to grow out & return) and what's done, and lets you
/// add or settle one. Local-first; reads the encrypted inventory DB.
class PlantaresScreen extends StatelessWidget {
const PlantaresScreen({super.key});
@override
Widget build(BuildContext context) {
final t = context.t;
final repo = context.read<VarietyRepository>();
return Scaffold(
appBar: AppBar(title: Text(t.plantare.title)),
floatingActionButton: FloatingActionButton.extended(
key: const Key('plantares.add'),
onPressed: () => showPlantareSheet(context, repository: repo),
icon: const Icon(Icons.add),
label: Text(t.plantare.add),
),
body: StreamBuilder<List<PlantareView>>(
stream: repo.watchPlantareViews(),
builder: (context, snapshot) {
final all = snapshot.data;
if (all == null) {
return const Center(child: CircularProgressIndicator());
}
if (all.isEmpty) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Text(
t.plantare.empty,
textAlign: TextAlign.center,
style: const TextStyle(color: seedMuted, fontSize: 15),
),
),
);
}
final open =
all.where((v) => v.plantare.status == PlantareStatus.open);
final settled =
all.where((v) => v.plantare.status != PlantareStatus.open);
return ListView(
padding: const EdgeInsets.only(bottom: 88),
children: [
if (open.isNotEmpty) _SectionHeader(t.plantare.openSection),
for (final v in open) _PlantareTile(v, repo),
if (settled.isNotEmpty) _SectionHeader(t.plantare.settledSection),
for (final v in settled) _PlantareTile(v, repo),
],
);
},
),
);
}
}
class _SectionHeader extends StatelessWidget {
const _SectionHeader(this.label);
final String label;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
child: Text(
label.toUpperCase(),
style: const TextStyle(
color: seedMuted,
fontSize: 12,
fontWeight: FontWeight.w600,
letterSpacing: 0.5,
),
),
);
}
/// One commitment row. An open one shows a big "mark returned"; a settled one
/// reads muted. It names the seed and (when linked) taps through to its detail,
/// shows when it was made and — for a promise with a return-by date — whether
/// it's still ahead or overdue. The overflow menu carries the rest (let go /
/// reopen / remove).
class _PlantareTile extends StatelessWidget {
const _PlantareTile(this.view, this.repo);
final PlantareView view;
final VarietyRepository repo;
@override
Widget build(BuildContext context) {
final t = context.t;
final p = view.plantare;
final varietyLabel = view.varietyLabel;
final done = p.status != PlantareStatus.open;
final iReturn = p.direction == PlantareDirection.iReturn;
final title = (p.owedDescription?.trim().isNotEmpty ?? false)
? p.owedDescription!.trim()
: (iReturn ? t.plantare.iReturn : t.plantare.owedToMe);
final locals = MaterialLocalizations.of(context);
final made = locals
.formatShortDate(DateTime.fromMillisecondsSinceEpoch(p.madeOn));
final subtitleParts = <String>[
iReturn ? t.plantare.iReturn : t.plantare.owedToMe,
?varietyLabel,
if (p.counterparty?.trim().isNotEmpty ?? false) p.counterparty!.trim(),
made,
if (done)
p.status == PlantareStatus.returned
? t.plantare.statusReturned
: t.plantare.statusForgiven,
];
// A return-by date is a gentle nudge, not a debt: only an open, past-due
// promise reads as overdue.
final overdue = !done &&
p.dueBy != null &&
p.dueBy! < DateTime.now().millisecondsSinceEpoch;
final returnBy = p.dueBy == null
? null
: t.plantare.returnBy(
date: locals.formatShortDate(
DateTime.fromMillisecondsSinceEpoch(p.dueBy!),
),
);
final linkedId = varietyLabel == null ? null : p.varietyId;
return ListTile(
onTap: linkedId == null ? null : () => context.push('/variety/$linkedId'),
leading: Icon(
iReturn ? Icons.volunteer_activism_outlined : Icons.eco_outlined,
color: done ? seedMuted : seedGreen,
),
title: Text(
title,
style: TextStyle(
decoration: done ? TextDecoration.lineThrough : null,
color: done ? seedMuted : seedOnSurface,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(subtitleParts.join(' · '),
maxLines: 2, overflow: TextOverflow.ellipsis),
if (returnBy != null)
Text(
overdue ? '$returnBy · ${t.plantare.overdue}' : returnBy,
style: TextStyle(
color: overdue ? seedWarning : seedMuted,
fontWeight: overdue ? FontWeight.w600 : null,
),
),
],
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (!done)
IconButton(
key: Key('plantare.return.${p.id}'),
icon: const Icon(Icons.check_circle_outline),
tooltip: t.plantare.markReturned,
color: seedGreen,
onPressed: () =>
repo.setPlantareStatus(p.id, PlantareStatus.returned),
),
PopupMenuButton<String>(
key: Key('plantare.menu.${p.id}'),
onSelected: (v) async {
switch (v) {
case 'forgiven':
await repo.setPlantareStatus(p.id, PlantareStatus.forgiven);
case 'reopen':
await repo.setPlantareStatus(p.id, PlantareStatus.open);
case 'delete':
await repo.deletePlantare(p.id);
}
},
itemBuilder: (context) => [
if (!done)
PopupMenuItem(
value: 'forgiven', child: Text(t.plantare.markForgiven)),
if (done)
PopupMenuItem(
value: 'reopen', child: Text(t.plantare.reopen)),
PopupMenuItem(value: 'delete', child: Text(t.plantare.delete)),
],
),
],
),
);
}
}