Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add presentation layer sample #6

Merged
merged 1 commit into from
Jun 24, 2023
Merged

add presentation layer sample #6

merged 1 commit into from
Jun 24, 2023

Conversation

trunghvbk
Copy link
Owner

#1
Referred articles: https://codewithandrea.com/articles/flutter-presentation-layer/
image

By implementing a custom controller class based on StateNotifier, we've separated our business logic from the UI code.

As a result, our widget class is now completely stateless and is only concerned with:

watching state changes and rebuilding as a result (with ref.watch)
responding to user input by calling methods in the controller (with ref.read)
listening to state changes and showing errors if something goes wrong (with ref.listen)
Meanwhile, the job of our controller is to:

talk to the repository on behalf of the widget
emit state changes as needed
And since the controller doesn't depend on any UI code, it can be easily unit tested.

This makes it an ideal place to store any widget-specific business logic.

@trunghvbk trunghvbk merged commit b7dd1e6 into main Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant