In this fourth part of the Clean Architecture series, we move into the layer that users directly interact with: the Presentation Layer. This is where UI, state management, and user-triggered logic come together.
Take a look at the previous related posts here: 101, 102, and 103.
What is the Presentation Layer?
The Presentation Layer is responsible for:
-
Displaying UI (Flutter widgets)
-
Reacting to user input
-
Managing and reflecting UI state
-
Interacting with Use Cases from the Domain Layer
It should not include:
-
Direct API calls
-
Business logic
-
Raw data models (DTOs)
Goals of the Presentation Layer
-
Keep UI logic separate from business logic
-
Make the UI reactive and testable
-
Provide a clear entry point into the use case(s)
Core Components
1. Views (Widgets)
These are your Flutter widgets that render the user interface. Views:
-
Call methods on the controller to perform actions
-
Read values (like
isLoading,user, orerror) exposed by the controller -
Do not contain business or data-fetching logic
2. Controllers (e.g., UserController)
Controllers act as an intermediary between the UI and the Domain Layer.
In this architecture, we do not create separate UI models. Instead:
-
We use domain entities (e.g.,
User) directly -
We manage UI-specific state (e.g., loading, error) alongside them
-
The controller calls use cases and updates the state accordingly
-
Listeners are notified of changes so the UI can update
Here’s an example:
Comments
Post a Comment