Clean Architecture components library, inspired on the guidelines created by Uncle Bob.
- Introduction, to understand the relationship between the components of the framework.
- Navigating with CFRouter, to start using high level Navigator 2.0 APIs bundled with Clean Framework.
- Mockoon Installation, since the tests in the example folder require an instance of Mockoon running.
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: clean_framework: ^0.4.0
2. Install it
You can install packages from the command line: with Flutter:
$ flutter pub get
Alternatively, your editor might support
flutter pub get. Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
Whatever name is used for
feature_name can replace
feature in the file names of the feature's directory
lib |-- feature_name | |-- api | | |-- feature_service.dart | | |-- feature_service_request.dart | | |-- feature_service_response.dart | |-- bloc | | |-- feature_bloc.dart | | |-- feature_service_adapter.dart | | |-- feature_usecase.dart | |-- model | | |-- feature_entity.dart | | |-- feature_view_model.dart | |-- ui | | |-- feature_widget.dart | | |-- feature_presenter.dart | | |-- feature_screen.dart locator.dart main.dart
The API module defines the logic for your API services, request, and response. The module defines the logic for REST API request and response that will be consumed by the Bloc.
- Every Feature Service class should extend EitherService<JsonRequestModel, JsonResponseModel> from
- Every Feature ServiceRequest class should extend Equatable and implement JsonRequestModel from
- Every Feature ServiceResponse class should extend Equatable and implement JsonResponseModel from
The Bloc module represents the logic of data flow within the application. It is the middle layer between the API and UI layers. The Bloc is responsible for updating the pipe when the data changes.
- Every Feature Bloc class should extend Bloc from
- Responsible for updating the ViewModel as the data coming from the API changes
- Every Feature ServiceAdapter should extend ServiceAdapter from
- Responsible for connecting the contents of the API and the UseCase
- Called when a UseCase requests data or sends data
- Every Feature UseCase should extend UseCase from
- Contains app-specific rules/commands
- Responsible for the flow of data within the app
The Model module defines the business logic of the application. This module consists of two main classes: Entity and ViewModel. The Entity class determines how the model class will be represented in the Repository (in locator.dart). The ViewModel class represents how the data is passed through to the UI. The Presenter passes the ViewModel to the Screen when the Presenter is called in the Widget.
- Every Feature Entity class should extend Entity from
- Made up of classes that represent the data in the Repository
- Every Feature ViewModel class should extend ViewModel from
- Made up of classes that represent how the data is presented to the UI
The UI module is responsible for all things UI, from triggering the bloc to update the UI, to painting the screen with data send from the UI.
- Every Feature Widget should extend StatelessWidget
- Responsible for kickstarting the Bloc and return the Presenter
- Is called in
main.dartwhen the feature is the first screen, or in a Navigator when switching to that feature
- Every Feature Presenter should extend Presenter from
- Responsible for calling appropriate methods as data reaches different stages
- Every Feature Screen should extend Screen from
- Responsible for building UI widgets; should not include any logic other than UI