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.
This commit is contained in:
vjrj 2026-07-13 18:06:33 +02:00
parent e57763d0a2
commit adf396d49d
21 changed files with 687 additions and 27 deletions

View file

@ -34,6 +34,7 @@ class _PlantareSheetState extends State<_PlantareSheet> {
final _counterparty = TextEditingController();
final _owed = TextEditingController();
final _note = TextEditingController();
DateTime? _dueBy;
bool _saving = false;
@override
@ -46,6 +47,17 @@ class _PlantareSheetState extends State<_PlantareSheet> {
String? _nullIfBlank(String s) => s.trim().isEmpty ? null : s.trim();
Future<void> _pickDueBy() async {
final now = DateTime.now();
final picked = await showDatePicker(
context: context,
initialDate: _dueBy ?? DateTime(now.year + 1, now.month, now.day),
firstDate: DateTime(now.year - 1),
lastDate: DateTime(now.year + 10),
);
if (picked != null) setState(() => _dueBy = picked);
}
Future<void> _save() async {
setState(() => _saving = true);
await widget.repository.createPlantare(
@ -53,6 +65,7 @@ class _PlantareSheetState extends State<_PlantareSheet> {
varietyId: widget.varietyId,
counterparty: _nullIfBlank(_counterparty.text),
owedDescription: _nullIfBlank(_owed.text),
dueBy: _dueBy?.millisecondsSinceEpoch,
note: _nullIfBlank(_note.text),
);
if (mounted) Navigator.of(context).pop();
@ -121,6 +134,43 @@ class _PlantareSheetState extends State<_PlantareSheet> {
),
),
const SizedBox(height: 12),
// Optional return-by date a gentle reminder, never enforced.
InputDecorator(
decoration: InputDecoration(
labelText: t.plantare.dueByLabel,
helperText: t.plantare.dueByHint,
border: const OutlineInputBorder(),
),
child: Row(
children: [
Expanded(
child: Text(
_dueBy == null
? t.plantare.pickDate
: MaterialLocalizations.of(context)
.formatShortDate(_dueBy!),
style: TextStyle(
color: _dueBy == null ? seedMuted : seedOnSurface,
),
),
),
if (_dueBy != null)
IconButton(
key: const Key('plantare.dueBy.clear'),
icon: const Icon(Icons.clear, size: 20),
tooltip: t.plantare.clearDate,
onPressed: () => setState(() => _dueBy = null),
),
IconButton(
key: const Key('plantare.dueBy.pick'),
icon: const Icon(Icons.event_outlined),
tooltip: t.plantare.pickDate,
onPressed: _pickDueBy,
),
],
),
),
const SizedBox(height: 12),
TextField(
key: const Key('plantare.note'),
controller: _note,

View file

@ -1,8 +1,8 @@
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/database.dart';
import '../db/enums.dart';
import '../i18n/strings.g.dart';
import 'plantare_sheet.dart';
@ -26,8 +26,8 @@ class PlantaresScreen extends StatelessWidget {
icon: const Icon(Icons.add),
label: Text(t.plantare.add),
),
body: StreamBuilder<List<Plantare>>(
stream: repo.watchPlantares(),
body: StreamBuilder<List<PlantareView>>(
stream: repo.watchPlantareViews(),
builder: (context, snapshot) {
final all = snapshot.data;
if (all == null) {
@ -45,15 +45,17 @@ class PlantaresScreen extends StatelessWidget {
),
);
}
final open = all.where((p) => p.status == PlantareStatus.open);
final settled = all.where((p) => p.status != PlantareStatus.open);
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 p in open) _PlantareTile(p, repo),
for (final v in open) _PlantareTile(v, repo),
if (settled.isNotEmpty) _SectionHeader(t.plantare.settledSection),
for (final p in settled) _PlantareTile(p, repo),
for (final v in settled) _PlantareTile(v, repo),
],
);
},
@ -82,30 +84,54 @@ class _SectionHeader extends StatelessWidget {
}
/// One commitment row. An open one shows a big "mark returned"; a settled one
/// reads muted. The overflow menu carries the rest (let go / reopen / remove).
/// 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.p, this.repo);
const _PlantareTile(this.view, this.repo);
final Plantare p;
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,
@ -117,8 +143,21 @@ class _PlantareTile extends StatelessWidget {
color: done ? seedMuted : seedOnSurface,
),
),
subtitle: Text(subtitleParts.join(' · '),
maxLines: 2, overflow: TextOverflow.ellipsis),
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: [

View file

@ -26,6 +26,7 @@ const seedOnSurfaceVariant = Color(0xFF5C6B52); // scientific names, secondary
const seedMuted = Color(0xFF617057);
const seedRating = Color(0xFFE8A200); // stars
const seedFavorite = Color(0xFFE53935); // saved/favorite heart (pops on green)
const seedWarning = Color(0xFFA84600); // overdue nudges (AA on white & canvas)
ThemeData buildTaneTheme() {
final scheme =

View file

@ -9,6 +9,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../data/seed_saving_catalog.dart';
import '../data/species_repository.dart';
import '../data/variety_repository.dart';
import '../db/database.dart';
import '../db/enums.dart';
import '../domain/crop_calendar.dart';
import '../domain/seed_saving.dart';
@ -235,6 +236,106 @@ class _DetailView extends StatelessWidget {
lot: lot,
viabilityYears: detail.viabilityYears,
),
_PlantaresSection(varietyId: detail.id),
],
),
);
}
}
/// The reproduction commitments (Plantarés) recorded against this variety so
/// a promise to grow it out and pass it on lives next to the seed it's about,
/// not only on the separate Plantares screen. Read-only: new ones are recorded
/// through the single hand-over door (or the Plantares screen), and the section
/// stays hidden until there's something to show, like the other detail blocks.
class _PlantaresSection extends StatelessWidget {
const _PlantaresSection({required this.varietyId});
final String varietyId;
@override
Widget build(BuildContext context) {
final t = context.t;
final repo = context.read<VarietyRepository>();
return StreamBuilder<List<Plantare>>(
stream: repo.watchPlantaresForVariety(varietyId),
builder: (context, snapshot) {
final list = snapshot.data ?? const <Plantare>[];
if (list.isEmpty) return const SizedBox.shrink();
return Column(
key: const Key('detail.plantares'),
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 16),
_SectionTitle(t.plantare.sectionTitle),
for (final p in list) _PlantareLine(p),
],
);
},
);
}
}
/// A compact, read-only commitment row for the variety detail: direction,
/// counterparty and when with a return-by line (amber when overdue).
class _PlantareLine extends StatelessWidget {
const _PlantareLine(this.p);
final Plantare p;
@override
Widget build(BuildContext context) {
final t = context.t;
final locals = MaterialLocalizations.of(context);
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 parts = <String>[
iReturn ? t.plantare.iReturn : t.plantare.owedToMe,
if (p.counterparty?.trim().isNotEmpty ?? false) p.counterparty!.trim(),
locals.formatShortDate(DateTime.fromMillisecondsSinceEpoch(p.madeOn)),
if (done)
p.status == PlantareStatus.returned
? t.plantare.statusReturned
: t.plantare.statusForgiven,
];
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!),
),
);
return ListTile(
contentPadding: EdgeInsets.zero,
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(parts.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,
),
),
],
),
);