DatabaseService class
Service for managing mosquito and disease data using SQLite database.
This singleton service provides CRUD operations for mosquito species and diseases, including multi-language support and relationship management between species and diseases. It handles database initialization, data population from JSON assets, and localized queries.
Database Schema
The service manages a normalized SQLite database with the following tables:
mosquito_species: Core species data (ID, scientific name, image URL)mosquito_species_translations: Localized species informationdiseases: Core disease data (ID, name key, image URL)disease_translations: Localized disease informationmosquito_disease_relation: Many-to-many relationships between species and diseases
Localization Support
All user-facing content supports multiple languages through translation tables:
- English (
en): Primary language with complete coverage - Spanish (
es): Full translation support - Russian (
ru): Full translation support
Data Sources
Initial data is populated from assets/database/database_data.json which contains:
- Species information from scientific literature
- Disease data from WHO and CDC sources
- Vector-disease relationships from epidemiological studies
Usage Example
final dbService = DatabaseService();
// Get all mosquito species in Spanish
final species = await dbService.getAllMosquitoSpecies('es');
// Find a specific species by scientific name
final aedes = await dbService.getMosquitoSpeciesByName('Aedes aegypti', 'en');
// Get diseases transmitted by a species
final diseases = await dbService.getDiseasesByVector('Aedes aegypti', 'en');
Performance Considerations
- Database is created once and cached for the app lifetime
- Queries use indexes on frequently accessed columns
- Batch operations are used for initial data population
- Connection pooling is handled by SQLite
See also:
- MosquitoRepository for higher-level data access patterns
- MosquitoSpecies and Disease for the data models
Constructors
- DatabaseService()
-
Gets the singleton instance of the database service.
factory
Properties
Methods
-
getAllDiseases(
String languageCode) → Future< List< Disease> > - Retrieves all diseases for a specific language.
-
getAllMosquitoSpecies(
String languageCode) → Future< List< MosquitoSpecies> > - Retrieves all mosquito species for a specific language.
-
getDiseaseById(
String id, String languageCode) → Future< Disease?> - Retrieves a specific disease by ID for a specific language.
-
getDiseasesByVector(
String speciesName, String languageCode) → Future< List< Disease> > - Retrieves diseases associated with a specific mosquito species.
-
getMosquitoSpeciesById(
String id, String languageCode) → Future< MosquitoSpecies?> - Retrieves a specific mosquito species by ID for a specific language.
-
getMosquitoSpeciesByName(
String scientificName, String languageCode) → Future< MosquitoSpecies?> - Retrieves a mosquito species by its scientific name for a specific language.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited