tane/apps/app_seeds/lib/ui/plantare_sheet.dart
vjrj 833ddaed4d 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).
2026-07-11 02:11:57 +02:00

145 lines
4.7 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();
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),
),
],
),
),
);
}
}