Pokedex
This task was quite an interesting one. As with all my projects, I started with understanding the scope and state of this app.
I decided to use the clean-architecture structure, for architecting the app. I built the app in these stages: UI -> Domain -> Data.
For a small-scale project like this, I concluded that using state-management libraries might be overkill, and went with using what Flutter has provided: ChangeNotifiers and InheritedWidget.
Structure
The sample structure of this project is displayed below:
integration_test/
|- app_test.dart
|- custom_finders_matchers.dart
|- detail_screen_test_cases.dart
|- home_screen_test_cases.dart
|
lib/
|- data
| |- entity_mapper.dart
| |- models
| |- data_sources
| |_repository_impl.dart
|
|- domain
| |- pokemon_entity.dart
| |_ repository_base.dart
|
|- presentation
| |- widgets
| | |_ widget_export.dart
| |
| |_ data_controllers.dart
| |_ data_provider.dart
| |_ detail_screen.dart
| |_ home_screen.dart
|
|- util
| |- colors.dart
| |- extensions.dart
| |- icon_util.dart
| |_util_export.dart
|
|_ main.dart
The presentation layer consists of all UI-related code, including UI logic. This layer depends on the Domain layer.
The domain layer bridge the presentation layer and the data layer. Since the presentation layer is only allowed to communicate with this layer. The base repository, entity(PokemonEntity), and entity mappers are defined here. The PokemonEntity is a simple data class that holds specific UI-related fields. It knows nothing about what the actual data coming from the server looks like. The mapper classes are provided to map a data model to an entity class.
The data layer holds all business logic. It's the backbone of any data-related task. It houses model data classes that parse JSON objects, an implementation of the repository, a data source, and a local data source.
The util folder contains some utilities used across apps, like colours, extensions, etc.
Packages used
The dependencies used are listed below:
- Google fonts: This package is included to utilise Noto Sans font for the application.
- Shimmer: The loading effect is handled by this package.
- Equatable: Provides easy implementation of value-based equality of different object types.