1.5 KiB
1.5 KiB
Application Architecture
Overview
The application follows a modular structure separated by responsibilities (models, pages, components, services).
Layers
1. Data Layer
- Models:
Pokemonclass defines the data structure for a Pokemon, including serialization/deserialization logic. - API:
PokemonApihandles communication with the Tyradex REST API using thehttppackage. - Database:
PokedexDatabasemanages local persistence using SQLite (sqflite). It uses batch operations for performance during initial sync.
2. Business Logic & State
- State Management: Uses Flutter's
StatefulWidgetandsetStatefor local page state. - Reactivity:
ValueNotifierin the database layer notifies the UI when data changes (e.g., catching a Pokemon updates the list). - Persistence:
shared_preferencesis used for simple key-value storage like best scores.
3. UI Layer
- Pages: Top-level screens like
MainPage,PokemonListPage, andGuessPage. - Components: Reusable UI elements like
PokemonTile. - Navigation: Managed in
MainPageusingIndexedStackto preserve tab state across navigation.
Data Flow
- At startup, the app checks the local database.
- If the database is missing generations, it fetches the full list from Tyradex API and performs a batch insert.
- User interactions (like a correct guess) update the local database.
- The database triggers a notification, causing relevant UI components to refresh their view.