feat(inventory): informal quantity scale (number + unit) + seed/plant lots
Rework quantities the way seeds are actually described — a number of an informal
unit — and let a lot hold seeds or plants (plantel).
Quantity model (commons_core):
- Quantity is now { kind, count?, label } — "3 cobs", "2 packets", "a few".
Count is optional; uncountable vibes (a few, some, pinch) carry no number.
- QuantityKind reorganised into an ascending scale: vibes → containers
(teaspoon/spoon/cup/jar/sack) → seed & fruit forms → plant units, each tagged
countable/not. Stored by name; count reuses the existing numeric column.
Lot type (schema v2):
- Lots gain a `type` (seed | plant); germination stays meaningful for seeds.
schemaVersion 2 with a from1To2 migration (adds the column), drift_schema_v2
exported, migration test covers v1→v2.
UI:
- New QuantityPicker: a horizontal scale of large seed-glyph icons + a number
stepper (shown only for countable units), plus a seed/plant SegmentedButton.
Used in quick-add and add-lot. Lot lines render "3 cobs" / "a few".
- i18n: unit singular/plural (ES/EN, Weblate-friendly), lot-type labels.
Build: slang moved to its CLI (disabled in build_runner to avoid a multi-file
collision); CI runs `dart run slang` before build_runner. 38 tests green,
Linux migrates the existing v1 DB and runs.
This commit is contained in:
parent
48e9d15772
commit
3942975dba
26 changed files with 4220 additions and 315 deletions
|
|
@ -4,11 +4,13 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||
|
||||
import '../data/species_repository.dart';
|
||||
import '../data/variety_repository.dart';
|
||||
import '../db/enums.dart';
|
||||
import '../i18n/strings.g.dart';
|
||||
import '../state/variety_detail_cubit.dart';
|
||||
import 'quantity_kind_l10n.dart';
|
||||
import 'quantity_picker.dart';
|
||||
import 'seed_glyph.dart';
|
||||
import 'theme.dart';
|
||||
import 'quantity_kind_l10n.dart';
|
||||
|
||||
/// Read + edit view of a single variety: its photo, category, notes, other
|
||||
/// names and lots. Edits go through [VarietyDetailCubit]; the view is reactive.
|
||||
|
|
@ -144,20 +146,11 @@ String _lotSubtitle(Translations t, VarietyLot lot) {
|
|||
t.detail.year(year: lot.harvestYear!)
|
||||
else
|
||||
t.detail.noYear,
|
||||
if (lot.quantity != null) _quantityLabel(t, lot.quantity!),
|
||||
if (lot.quantity != null) quantityDisplay(t, lot.quantity!),
|
||||
];
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
String _quantityLabel(Translations t, Quantity q) {
|
||||
final kind = quantityKindLabel(t, q.kind);
|
||||
if (q.precise != null) return '${_trimDouble(q.precise!)} $kind';
|
||||
return kind;
|
||||
}
|
||||
|
||||
String _trimDouble(double v) =>
|
||||
v == v.roundToDouble() ? v.toStringAsFixed(0) : v.toString();
|
||||
|
||||
String _germinationPercent(Translations t, double rate) =>
|
||||
t.germination.result(percent: (rate * 100).round());
|
||||
|
||||
|
|
@ -485,7 +478,8 @@ class _EditVarietySheetState extends State<_EditVarietySheet> {
|
|||
Future<void> _showAddLotSheet(BuildContext context, VarietyDetailCubit cubit) {
|
||||
final t = context.t;
|
||||
final yearController = TextEditingController();
|
||||
QuantityKind? selectedKind;
|
||||
var selectedType = LotType.seed;
|
||||
Quantity? selectedQuantity;
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
|
|
@ -506,6 +500,14 @@ Future<void> _showAddLotSheet(BuildContext context, VarietyDetailCubit cubit) {
|
|||
style: Theme.of(sheetContext).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
LotTypeSelector(
|
||||
value: selectedType,
|
||||
onChanged: (type) => setState(() {
|
||||
selectedType = type;
|
||||
selectedQuantity = null;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
key: const Key('addLot.year'),
|
||||
controller: yearController,
|
||||
|
|
@ -521,17 +523,10 @@ Future<void> _showAddLotSheet(BuildContext context, VarietyDetailCubit cubit) {
|
|||
style: Theme.of(sheetContext).textTheme.labelLarge,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (final kind in _addLotKinds)
|
||||
ChoiceChip(
|
||||
avatar: QuantityKindIcon(kind, size: 18),
|
||||
label: Text(quantityKindLabel(t, kind)),
|
||||
selected: selectedKind == kind,
|
||||
onSelected: (_) => setState(() => selectedKind = kind),
|
||||
),
|
||||
],
|
||||
QuantityPicker(
|
||||
type: selectedType,
|
||||
value: selectedQuantity,
|
||||
onChanged: (q) => selectedQuantity = q,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
|
|
@ -545,10 +540,9 @@ Future<void> _showAddLotSheet(BuildContext context, VarietyDetailCubit cubit) {
|
|||
key: const Key('addLot.save'),
|
||||
onPressed: () {
|
||||
cubit.addLot(
|
||||
type: selectedType,
|
||||
year: int.tryParse(yearController.text.trim()),
|
||||
quantity: selectedKind == null
|
||||
? null
|
||||
: Quantity(kind: selectedKind!),
|
||||
quantity: selectedQuantity,
|
||||
);
|
||||
Navigator.of(sheetContext).pop();
|
||||
},
|
||||
|
|
@ -563,15 +557,6 @@ Future<void> _showAddLotSheet(BuildContext context, VarietyDetailCubit cubit) {
|
|||
);
|
||||
}
|
||||
|
||||
const _addLotKinds = <QuantityKind>[
|
||||
QuantityKind.aFew,
|
||||
QuantityKind.handful,
|
||||
QuantityKind.packet,
|
||||
QuantityKind.pod,
|
||||
QuantityKind.cob,
|
||||
QuantityKind.grams,
|
||||
];
|
||||
|
||||
String? _nullIfBlank(String value) {
|
||||
final trimmed = value.trim();
|
||||
return trimmed.isEmpty ? null : trimmed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue