feat(seed-saving): per-crop 'how to save this seed' guidance
A bundled, curated knowledge layer — the differentiator of a serious seed app. For a variety's crop it shows how the plant reproduces and what it takes to keep the variety true: life cycle, pollination (self/cross + insect/wind), isolation distance, how many plants to save from, dry/wet processing, a difficulty pill, and a short tip — all in human words. - assets/catalog/seed_saving.json: curated public-domain data (Seed to Seed / Seed Savers), keyed by botanical FAMILY (defaults) with per-species/genus OVERRIDES that win — so e.g. Vicia faba is correctly insect-cross-pollinated despite the selfing Fabaceae default, and maize is wind-pollinated with a large population. Notes are locale-keyed (es/en), extensible to any language — a starter set, not a ceiling. - domain/seed_saving.dart (pure): enums + SeedSavingGuide (merge, note fallback) + SeedSavingData.guideFor (species → genus → family). - data/seed_saving_catalog.dart: loads the asset once into an in-memory singleton (no DB table, no migration); injector loads it at startup. - VarietyDetail gains (from the linked species — the reliable key, vs the editable category); detail screen shows a _SeedSavingView when a guide resolves. - i18n seedSaving block (labels + enum values + params) in en/es/pt/ast. - Tests: domain lookup/merge, the real asset's key corrections, and the detail section shows/hides. 314 suite tests green; analyze clean.
This commit is contained in:
parent
bfff95fe8d
commit
7c2e3f207f
19 changed files with 954 additions and 2 deletions
|
|
@ -6,10 +6,12 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
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/enums.dart';
|
||||
import '../domain/crop_calendar.dart';
|
||||
import '../domain/seed_saving.dart';
|
||||
import '../domain/seed_viability.dart';
|
||||
import '../domain/species_reference_links.dart';
|
||||
import '../i18n/strings.g.dart';
|
||||
|
|
@ -147,6 +149,14 @@ class _DetailView extends StatelessWidget {
|
|||
_SectionTitle(t.cropCalendar.title),
|
||||
_CropCalendarView(detail: detail),
|
||||
],
|
||||
if (SeedSavingCatalog.guideFor(
|
||||
scientificName: detail.scientificName,
|
||||
family: detail.family ?? detail.category,
|
||||
) case final guide? when guide.hasAny) ...[
|
||||
const SizedBox(height: 16),
|
||||
_SectionTitle(t.seedSaving.title),
|
||||
_SeedSavingView(guide: guide),
|
||||
],
|
||||
if (_referenceLinks(context, detail) case final references
|
||||
when references.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
|
|
@ -1010,6 +1020,141 @@ class _CropCalendarView extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
/// "How to save this seed" — the bundled seed-saving guidance for the crop
|
||||
/// (pollination, isolation distance, how many plants, wet/dry, difficulty, a
|
||||
/// tip), in human words. Shown only when a guide resolves for the variety.
|
||||
class _SeedSavingView extends StatelessWidget {
|
||||
const _SeedSavingView({required this.guide});
|
||||
|
||||
final SeedSavingGuide guide;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final t = context.t;
|
||||
final rows = <Widget>[];
|
||||
|
||||
final cycle = switch (guide.lifeCycle) {
|
||||
LifeCycle.annual => t.seedSaving.cycleAnnual,
|
||||
LifeCycle.biennial => t.seedSaving.cycleBiennial,
|
||||
LifeCycle.perennial => t.seedSaving.cyclePerennial,
|
||||
null => null,
|
||||
};
|
||||
if (cycle != null) {
|
||||
rows.add(_line(Icons.event_repeat, t.seedSaving.lifeCycle, cycle));
|
||||
}
|
||||
|
||||
if (guide.pollination case final poll?) {
|
||||
final base = switch (poll) {
|
||||
Pollination.self => t.seedSaving.pollSelf,
|
||||
Pollination.cross => t.seedSaving.pollCross,
|
||||
Pollination.mixed => t.seedSaving.pollMixed,
|
||||
};
|
||||
final via = poll == Pollination.self
|
||||
? ''
|
||||
: switch (guide.vector) {
|
||||
PollinationVector.insect => ' · ${t.seedSaving.byInsect}',
|
||||
PollinationVector.wind => ' · ${t.seedSaving.byWind}',
|
||||
_ => '',
|
||||
};
|
||||
final icon = switch (guide.vector) {
|
||||
PollinationVector.wind => Icons.air,
|
||||
PollinationVector.insect => Icons.emoji_nature,
|
||||
_ => Icons.lock_outline,
|
||||
};
|
||||
rows.add(_line(icon, t.seedSaving.pollination, '$base$via'));
|
||||
}
|
||||
|
||||
if (guide.isolationMinM case final min?) {
|
||||
final max = guide.isolationMaxM;
|
||||
final value = (max != null && max != min)
|
||||
? t.seedSaving.isolationRange(min: min, max: max)
|
||||
: t.seedSaving.isolationSingle(min: min);
|
||||
rows.add(_line(Icons.social_distance, t.seedSaving.isolation, value));
|
||||
}
|
||||
|
||||
if ((guide.recommendedPlants ?? guide.minPlants) case final n?) {
|
||||
rows.add(_line(
|
||||
Icons.groups_outlined, t.seedSaving.plants, t.seedSaving.plantsValue(n: n)));
|
||||
}
|
||||
|
||||
if (guide.processing case final proc?) {
|
||||
final wet = proc == SeedProcessing.wet;
|
||||
rows.add(_line(wet ? Icons.water_drop_outlined : Icons.grass,
|
||||
t.seedSaving.processing, wet ? t.seedSaving.procWet : t.seedSaving.procDry));
|
||||
}
|
||||
|
||||
final note = guide.noteFor(LocaleSettings.currentLocale.languageCode);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
...rows,
|
||||
if (guide.difficulty case final d?) ...[
|
||||
const SizedBox(height: 4),
|
||||
_DifficultyChip(difficulty: d),
|
||||
],
|
||||
if (note != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(note, style: const TextStyle(color: seedMuted, height: 1.35)),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _line(IconData icon, String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, size: 18, color: seedGreen),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text.rich(TextSpan(children: [
|
||||
TextSpan(
|
||||
text: '$label · ',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
TextSpan(text: value),
|
||||
])),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _DifficultyChip extends StatelessWidget {
|
||||
const _DifficultyChip({required this.difficulty});
|
||||
|
||||
final SavingDifficulty difficulty;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final t = context.t;
|
||||
final (label, color) = switch (difficulty) {
|
||||
SavingDifficulty.easy => (t.seedSaving.diffEasy, const Color(0xFF3B6D11)),
|
||||
SavingDifficulty.medium =>
|
||||
(t.seedSaving.diffMedium, const Color(0xFF8A6D1E)),
|
||||
SavingDifficulty.hard => (t.seedSaving.diffHard, const Color(0xFFA14234)),
|
||||
};
|
||||
return Row(
|
||||
children: [
|
||||
Icon(Icons.insights, size: 18, color: seedGreen),
|
||||
const SizedBox(width: 10),
|
||||
Text('${t.seedSaving.difficulty} · ',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.14),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(label,
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Human label for a coarse-abundance level.
|
||||
String abundanceLabel(Translations t, Abundance a) => switch (a) {
|
||||
Abundance.plentyToShare => t.abundance.plentyToShare,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue