How raaz0n/country_list works
Project Type & Purpose
• This is a Flutter mobile application (with additional support for web, desktop: Android, iOS, Windows, macOS, and Linux) that displays a list of countries fetched from the Rest Countries API.
• The user can rename one or more items from the fetched list. The application uses local storage (with Hive) to save these changes and displays the locally stored country names on a separate page.
• It follows Clean Architecture principles with distinct separation into Presentation, Domain, and Data layers. Bloc is used for state management.
File Structure
• Top-Level Directories: Notice the “android”, “ios”, “macos”, “linux”, “windows”, and “web” directories which are platform-specific. The main application logic resides in the “lib” directory.
• Under “lib/src”, the project is divided into:
• Common utilities (constants, core functionalities, themes, etc.)
• Dependency Injection (using GetIt)
• Features → “country_list” which is further divided into:
• Data Layer: Contains subdirectories for data sources (both remote for API calls and local for Hive database operations), models, repositories implementations, and table definitions.
• Domain Layer: Contains entities, repository abstract definitions, and usecases corresponding to the app’s business logic.
• Presentation Layer: Contains Bloc implementations (for both displaying countries and saving country names), pages (UI screens), and widgets.
• The presence of specific files like MainActivity.kt, AppDelegate.swift, and build scripts shows how the app is built for multiple platforms.
Components and Their Relationships
a. Main Components:
• Presentation Layer:
• UI Pages (home_pages.dart, save_country_screen.dart)
• Widgets (alert_dialog_widget.dart, text_widget.dart)
• Bloc components: country_bloc (with events and states) and save_country_bloc managing user interactions.
• Domain Layer:
• Usecases: get_country, get_local_countries, save_country (representing business logic).
• Entities: country_entity, app_error, etc.
• Abstract Repository (country_repositories)
• Data Layer:
• Data Sources: country_remote_data_source for API calls; country_local_data_sources for local Hive operations.
• Models: country_model and its generated code for serialization.
• Repository Implementation: country_repositories_impl that implements the domain’s repository interface.
• Local Database Table: Defined by country_table and its generated code.
• External Services:
• Rest Countries API (external dependency for country data)
• Hive as the local database (files like countrybox.hive in the data folder)
b. Relationships:
• The Presentation Layer (UI) dispatches events to the Bloc.
• The Bloc communicates with the Domain Layer by calling usecases.
• Usecases interact with the Repository abstraction defined in the Domain Layer.
• The Repository Implementation in the Data Layer handles data fetching by choosing between the remote source (API) and the local source (Hive).
• Dependency Injection (via get_it.dart) wires these classes together.
• Data flows from an external API to the Data Layer, then up to the UI presentation.
Architectural Patterns and Technologies
• Clean Architecture: Clearly separates concerns into Presentation, Domain, and Data layers.
• Bloc Pattern for state management in the Presentation Layer.
• Dependency Injection with GetIt.
• Use of Hive for local storage.
• API integration with the Rest Countries API.
• Unit and Widget tests are also present for validating the different layers, ensuring the design can be tested independently.