feat(plantare): usable UI — commitments screen, add sheet, entry points

The reproduction-commitment (Plantare) UI, local-first and plain-spoken:
- A Plantares screen (drawer entry, /plantares) listing your commitments,
  grouped Open / Done, with a big 'mark returned', a menu (let it go / reopen
  / remove) and an empty-state that explains what a Plantare is.
- An add sheet (scrollable): a two-choice 'who reproduces & returns' (I return
  / owed to me), an optional 'with whom', an optional 'what comes back' in the
  grower's own words, and a note. No sale, no currency — a promise.
- Reachable from a seed too: an 'Add a commitment' action on the variety
  detail, pre-attached to that variety.
- i18n en/es/pt/ast (human words: 'Plantare' + a plain explanation).

Added the Plantares screen to the small-phone overflow guard (18 cases green).
This commit is contained in:
vjrj 2026-07-11 02:11:57 +02:00
parent 81094f25a8
commit de6938d5d7
15 changed files with 730 additions and 2 deletions

View file

@ -35,6 +35,15 @@ class AppDrawer extends StatelessWidget {
context.push('/inventory');
},
),
// Local, works offline a reproduction-commitment ledger.
_DrawerItem(
icon: const Icon(Icons.volunteer_activism_outlined),
label: t.menu.plantares,
onTap: () {
Navigator.of(context).pop();
context.push('/plantares');
},
),
_DrawerItem(
icon: const Icon(Symbols.storefront),
label: t.menu.market,

View file

@ -0,0 +1,145 @@
import 'package:flutter/material.dart';
import '../data/variety_repository.dart';
import '../db/enums.dart';
import '../i18n/strings.g.dart';
import 'theme.dart';
/// Opens the "add a Plantare" sheet a reproduction commitment. Optionally
/// pre-attached to [varietyId] (when opened from a variety's detail).
Future<void> showPlantareSheet(
BuildContext context, {
required VarietyRepository repository,
String? varietyId,
}) {
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
builder: (_) => _PlantareSheet(repository: repository, varietyId: varietyId),
);
}
class _PlantareSheet extends StatefulWidget {
const _PlantareSheet({required this.repository, this.varietyId});
final VarietyRepository repository;
final String? varietyId;
@override
State<_PlantareSheet> createState() => _PlantareSheetState();
}
class _PlantareSheetState extends State<_PlantareSheet> {
PlantareDirection _direction = PlantareDirection.iReturn;
final _counterparty = TextEditingController();
final _owed = TextEditingController();
final _note = TextEditingController();
bool _saving = false;
@override
void dispose() {
_counterparty.dispose();
_owed.dispose();
_note.dispose();
super.dispose();
}
String? _nullIfBlank(String s) => s.trim().isEmpty ? null : s.trim();
Future<void> _save() async {
setState(() => _saving = true);
await widget.repository.createPlantare(
direction: _direction,
varietyId: widget.varietyId,
counterparty: _nullIfBlank(_counterparty.text),
owedDescription: _nullIfBlank(_owed.text),
note: _nullIfBlank(_note.text),
);
if (mounted) Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
final t = context.t;
return Padding(
padding: EdgeInsets.only(
left: 16,
right: 16,
top: 16,
bottom: MediaQuery.of(context).viewInsets.bottom + 16,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(t.plantare.add,
style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 4),
Text(t.plantare.help,
style: const TextStyle(color: seedMuted, fontSize: 13)),
const SizedBox(height: 16),
Text(t.plantare.direction,
style: Theme.of(context).textTheme.labelLarge),
const SizedBox(height: 6),
// Two big, human choices no jargon.
for (final d in PlantareDirection.values)
ListTile(
key: Key('plantare.direction.${d.name}'),
contentPadding: EdgeInsets.zero,
leading: Icon(
_direction == d
? Icons.radio_button_checked
: Icons.radio_button_unchecked,
color: _direction == d ? seedGreen : seedMuted,
),
title: Text(d == PlantareDirection.iReturn
? t.plantare.iReturn
: t.plantare.owedToMe),
onTap: () => setState(() => _direction = d),
),
const SizedBox(height: 8),
TextField(
key: const Key('plantare.counterparty'),
controller: _counterparty,
textCapitalization: TextCapitalization.words,
decoration: InputDecoration(
labelText: t.plantare.counterparty,
helperText: t.plantare.counterpartyHint,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 12),
TextField(
key: const Key('plantare.owed'),
controller: _owed,
decoration: InputDecoration(
labelText: t.plantare.owed,
helperText: t.plantare.owedHint,
helperMaxLines: 2,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 12),
TextField(
key: const Key('plantare.note'),
controller: _note,
minLines: 1,
maxLines: 3,
decoration: InputDecoration(
labelText: t.plantare.note,
border: const OutlineInputBorder(),
),
),
const SizedBox(height: 20),
FilledButton(
key: const Key('plantare.save'),
onPressed: _saving ? null : _save,
child: Text(t.plantare.save),
),
],
),
),
);
}
}

View file

@ -0,0 +1,160 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../data/variety_repository.dart';
import '../db/database.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<Plantare>>(
stream: repo.watchPlantares(),
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((p) => p.status == PlantareStatus.open);
final settled = all.where((p) => p.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),
if (settled.isNotEmpty) _SectionHeader(t.plantare.settledSection),
for (final p in settled) _PlantareTile(p, 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. The overflow menu carries the rest (let go / reopen / remove).
class _PlantareTile extends StatelessWidget {
const _PlantareTile(this.p, this.repo);
final Plantare p;
final VarietyRepository repo;
@override
Widget build(BuildContext context) {
final t = context.t;
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 subtitleParts = <String>[
iReturn ? t.plantare.iReturn : t.plantare.owedToMe,
if (p.counterparty?.trim().isNotEmpty ?? false) p.counterparty!.trim(),
if (done)
p.status == PlantareStatus.returned
? t.plantare.statusReturned
: t.plantare.statusForgiven,
];
return ListTile(
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: Text(subtitleParts.join(' · '),
maxLines: 2, overflow: TextOverflow.ellipsis),
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)),
],
),
],
),
);
}
}

View file

@ -16,6 +16,7 @@ import '../i18n/strings.g.dart';
import '../state/variety_detail_cubit.dart';
import 'harvest_date_picker.dart';
import 'photo_pick.dart';
import 'plantare_sheet.dart';
import 'quantity_kind_l10n.dart';
import 'quantity_picker.dart';
import 'seed_glyph.dart';
@ -108,6 +109,21 @@ class _DetailView extends StatelessWidget {
),
],
),
const SizedBox(height: 16),
_SectionTitle(t.plantare.title),
Align(
alignment: AlignmentDirectional.centerStart,
child: OutlinedButton.icon(
key: const Key('detail.addPlantare'),
icon: const Icon(Icons.volunteer_activism_outlined, size: 18),
onPressed: () => showPlantareSheet(
context,
repository: context.read<VarietyRepository>(),
varietyId: detail.id,
),
label: Text(t.plantare.add),
),
),
if (detail.notes != null && detail.notes!.trim().isNotEmpty) ...[
const SizedBox(height: 16),
_SectionTitle(t.detail.notes),