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.
33 lines
1.2 KiB
Dart
33 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/services.dart' show rootBundle;
|
|
|
|
import 'species_repository.dart';
|
|
|
|
const _catalogAsset = 'assets/catalog/species.json';
|
|
|
|
/// Parses the bundled catalog JSON into [SpeciesSeed]s. Kept separate from asset
|
|
/// loading so it is trivially unit-testable without a Flutter binding.
|
|
List<SpeciesSeed> parseSpeciesCatalog(String jsonString) {
|
|
final data = jsonDecode(jsonString) as Map<String, dynamic>;
|
|
final entries = (data['species'] as List).cast<Map<String, dynamic>>();
|
|
return entries.map((e) {
|
|
final common = (e['common'] as Map<String, dynamic>? ?? const {}).map(
|
|
(lang, names) => MapEntry(lang, (names as List).cast<String>()),
|
|
);
|
|
return SpeciesSeed(
|
|
scientificName: e['scientific_name'] as String,
|
|
family: e['family'] as String?,
|
|
commonNames: common,
|
|
viabilityYears: (e['viability_years'] as num?)?.toInt(),
|
|
gbifKey: (e['gbif_key'] as num?)?.toInt(),
|
|
wikidataQid: e['wikidata_qid'] as String?,
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
/// Loads and parses the bundled species catalog asset.
|
|
Future<List<SpeciesSeed>> loadBundledSpecies() async {
|
|
final jsonString = await rootBundle.loadString(_catalogAsset);
|
|
return parseSpeciesCatalog(jsonString);
|
|
}
|