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.
195 lines
6.6 KiB
Dart
195 lines
6.6 KiB
Dart
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();
|
|
DateTime? _dueBy;
|
|
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> _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(
|
|
direction: _direction,
|
|
varietyId: widget.varietyId,
|
|
counterparty: _nullIfBlank(_counterparty.text),
|
|
owedDescription: _nullIfBlank(_owed.text),
|
|
dueBy: _dueBy?.millisecondsSinceEpoch,
|
|
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),
|
|
// 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,
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|