Add a small curated catalog of Iberian horticultural species and let a variety be linked to it from the edit sheet. - assets/catalog/species.json: 14 species with botanical family and ES/EN common names (wikidata_qid/gbif_key deferred to the varilla enrichment). - SpeciesRepository: idempotent seedBundled (is_bundled rows, keyed by scientific name) + search by scientific/common name with a locale-best label. Seeded on startup from DI. - VarietyRepository.linkSpecies: sets species_id and prefills category from the species' family when empty (never overwrites an existing category). VarietyDetail now carries the scientific name. - Edit sheet gains a live species-search field; the detail view shows the scientific name (italic). i18n strings added (ES/EN). Tests: catalog parse, idempotent seeding, search by scientific/common name, linkSpecies prefill semantics, and a widget test for the autocomplete → link → scientific-name-shown flow. Full suite: 32 passing, 0 skipped.
30 lines
1.1 KiB
Dart
30 lines
1.1 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,
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
/// Loads and parses the bundled species catalog asset.
|
|
Future<List<SpeciesSeed>> loadBundledSpecies() async {
|
|
final jsonString = await rootBundle.loadString(_catalogAsset);
|
|
return parseSpeciesCatalog(jsonString);
|
|
}
|