feat(species): derived verified reference links (GBIF/Wikipedia/Wikispecies)
Add a read-only "Learn more" section on the variety detail that surfaces verified external references for the linked species, built deterministically from bundled identifiers — no titles bundled, no network, offline-first: - GBIF taxon page from the backbone key - Wikipedia via Wikidata Special:GoToLinkedPage (locale-aware, RTL-safe, falls back to the Wikidata item when a language lacks the article) - Wikispecies from the scientific name Enrich the bundled catalog (species.json v3) with gbif_key + wikidata_qid for all 14 species, cross-checked (each QID carries GBIF ID P846 = the key). Schema already had the columns; seedBundled now persists and backfills them. The grower's own manual links stay but are demoted (progressive disclosure): the section only shows when links exist and "Add link" is a low-emphasis button, since hand-adding a link is the rarer power move. Pure-Dart link builder is unit-tested; repo persistence/backfill and the detail-screen section are covered too.
This commit is contained in:
parent
ba87bf2719
commit
fde0ea6eab
14 changed files with 484 additions and 46 deletions
|
|
@ -10,6 +10,8 @@ class SpeciesSeed {
|
|||
this.family,
|
||||
this.commonNames = const {},
|
||||
this.viabilityYears,
|
||||
this.gbifKey,
|
||||
this.wikidataQid,
|
||||
});
|
||||
|
||||
final String scientificName;
|
||||
|
|
@ -20,6 +22,13 @@ class SpeciesSeed {
|
|||
|
||||
/// Typical seed longevity in years (bundled reference data); null if unknown.
|
||||
final int? viabilityYears;
|
||||
|
||||
/// GBIF backbone taxon key; null if unknown. Feeds the derived reference link.
|
||||
final int? gbifKey;
|
||||
|
||||
/// Wikidata item id (e.g. `Q23501`); null if unknown. Feeds the derived
|
||||
/// Wikipedia (locale-aware) reference link.
|
||||
final String? wikidataQid;
|
||||
}
|
||||
|
||||
/// A catalog match surfaced to the UI (with a best common name for the locale).
|
||||
|
|
@ -63,13 +72,28 @@ class SpeciesRepository {
|
|||
..where((s) => s.scientificName.equals(seed.scientificName)))
|
||||
.getSingleOrNull();
|
||||
if (existing != null) {
|
||||
// Backfill bundled reference data added after the row was seeded.
|
||||
if (existing.viabilityYears == null && seed.viabilityYears != null) {
|
||||
// Backfill bundled reference data added after the row was seeded, so
|
||||
// it reaches installs seeded before these fields were bundled. Each
|
||||
// field is only written when the row still lacks it.
|
||||
final backfill = SpeciesCompanion(
|
||||
viabilityYears:
|
||||
existing.viabilityYears == null && seed.viabilityYears != null
|
||||
? Value(seed.viabilityYears)
|
||||
: const Value.absent(),
|
||||
gbifKey: existing.gbifKey == null && seed.gbifKey != null
|
||||
? Value(seed.gbifKey)
|
||||
: const Value.absent(),
|
||||
wikidataQid:
|
||||
existing.wikidataQid == null && seed.wikidataQid != null
|
||||
? Value(seed.wikidataQid)
|
||||
: const Value.absent(),
|
||||
);
|
||||
if (backfill.viabilityYears.present ||
|
||||
backfill.gbifKey.present ||
|
||||
backfill.wikidataQid.present) {
|
||||
await (_db.update(
|
||||
_db.species,
|
||||
)..where((s) => s.id.equals(existing.id))).write(
|
||||
SpeciesCompanion(viabilityYears: Value(seed.viabilityYears)),
|
||||
);
|
||||
)..where((s) => s.id.equals(existing.id))).write(backfill);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -87,6 +111,8 @@ class SpeciesRepository {
|
|||
family: Value(seed.family),
|
||||
isBundled: const Value(true),
|
||||
viabilityYears: Value(seed.viabilityYears),
|
||||
gbifKey: Value(seed.gbifKey),
|
||||
wikidataQid: Value(seed.wikidataQid),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue