clean-flutter-app

repository·master·Indexed 20 days ago

https://github.com/rmanguinho/clean-flutter-app

A reference Flutter application demonstrating Clean Architecture, TDD, and SOLID principles. Developed as part of a professional training course by Rodrigo Manguinho, the project implements various design patterns (Factory, Adapter, Decorator, etc.) and utilizes Dart 2.14.2 and Flutter 2.5.1. It features a decoupled architecture with a custom HttpAdapter for network requests, an AuthorizeHttpClientDecorator for token management, and a routing system based on GetX.

Tokens
9.4K
Snippets
7
Records
46
Agent score
70%

What's inside clean-flutter-app

  1. Overview of Clean Flutter App

    master

    The clean-flutter-app is a reference implementation used in Rodrigo Manguinho's (Mango) Flutter training on Udemy. It serves as a practical example of building a Flutter application using a well-defined, decoupled architecture.

    Key characteristics of this project include:

    • Clean Architecture: Used to distribute responsibilities across distinct layers.
    • TDD (Test-Driven Development): The primary methodology for development.
    • SOLID Principles: Strict adherence to object-oriented design principles.
    • Design Patterns: Implementation of various patterns to solve common software engineering problems.
  2. Understand the Remote Load Survey Result use case

    master

    The Remote Load Survey Result use case describes the workflow for fetching and validating survey results from a remote API.

    Success Flow

    1. The system makes a request to the survey result API URL.
    2. The system validates the access token to ensure the user has permission to view the data.
    3. The system validates the data received from the API.
    4. The system delivers the survey result data.

    Error Handling (Exceptions)

    • Invalid URL: Returns an unexpected error message.
    • Access Denied: Returns an access denied message.
    • Invalid Response: Returns an unexpected error message.
    • Server Failure: Returns an unexpected error message.
  3. Use Case: Local Save Current Account

    master

    The Local Save Current Account use case is responsible for securely persisting the user's access token into the local cache.

    Success Scenario

    • The system successfully writes the user's access token to the cache in a secure manner.

    Exception Scenario

    • Failure to write to cache: If the cache operation fails, the system must return an unexpected error message.
  4. Understand the Local Load Current Account Use Case

    master

    The Local Load Current Account use case is responsible for retrieving the currently logged-in user's account information from local storage.

    Success Scenario

    1. The system requests the user's access token stored in the Secure Cache.
    2. The system successfully returns the user's account data.

    Exception Scenario: Cache Loading Failure

    1. If the system fails to load data from the cache, it returns an unexpected error message.
  5. Remote Authentication Use Case requirements

    master

    The Remote Authentication use case defines the expected behavior for authenticating a user via an external API. It covers both the successful authentication flow and various error scenarios that the system must handle.

    Success Flow

    1. Validate input data.
    2. Execute a request to the API login URL.
    3. Validate the data received from the API.
    4. Deliver the user account data.

    Error Handling (Exceptions)

    The system must return an unexpected error message for the following scenarios:

    • Invalid URL
    • Invalid input data
    • Invalid API response
    • Server failure

    Specifically for invalid credentials, the system must return a specific error message informing the user that the credentials are incorrect.

  6. Understand the Remote Add Account Use Case behavior

    master

    The Remote Add Account use case handles the process of registering a new user via a remote API. It follows a specific success and error flow:

    Success Flow

    1. Data Validation: The system validates the input data.
    2. API Request: The system sends a request to the signup API URL.
    3. Response Validation: The system validates the data received from the API.
    4. Data Delivery: The system returns the user account data.

    Error Handling (Exceptions)

    The use case is designed to catch and handle several failure scenarios by returning error messages:

    • Invalid URL: Returns an unexpected error message.
    • Invalid Data: Returns an unexpected error message.
    • Invalid Response: Returns an unexpected error message.
    • Server Failure: Returns an unexpected error message.
    • Email Already in Use: Returns a specific error message informing that the email is already registered.
  7. Validate surveys in local cache

    master

    The Local Validate Surveys use case ensures that the data currently held in the local cache is valid and usable.

    Success Scenario:

    • The system requests survey data from the cache and successfully validates the received data.

    Error Scenarios:

    • Error loading cache data: If an error occurs while attempting to load the cache, the system clears the cache data.
    • Invalid data in cache: If the data retrieved from the cache is found to be invalid, the system clears the cache data.
  8. Understand the Remote Load Surveys use case

    master

    The Remote Load Surveys use case describes the process of fetching survey data from a remote API. The system follows a specific lifecycle to ensure data integrity and security:

    1. API Request: The system makes a request to the designated Survey API URL.
    2. Token Validation: The system validates the access token to ensure the user has permission to view the data.
    3. Data Validation: The system validates the structure and content of the data received from the API.
    4. Data Delivery: Once validated, the system delivers the survey data to the application.

    Error Handling Behavior

    The system is designed to handle several failure scenarios with specific error responses:

    ScenarioSystem Response
    Invalid URLReturns an unexpected error message
    Access DeniedReturns an access denied message
    Invalid ResponseReturns an unexpected error message
    Server FailureReturns an unexpected error message
  9. Understand the Remote Save Survey Result use case

    master

    The Remote Save Survey Result use case describes the flow for retrieving survey result data from a remote API.

    Success Flow

    1. The system makes a request to the API URL for saving/retrieving survey results.
    2. The system validates the access token to ensure the user has permission to view the data.
    3. The system validates the data received from the API.
    4. The system delivers the survey result data.

    Error Handling

    The system handles the following failure scenarios by returning error messages:

    • Invalid URL: Returns an unexpected error message.
    • Access Denied: Returns an access denied message.
    • Invalid Response: Returns an unexpected error message.
    • Server Failure: Returns an unexpected error message.
  10. Implement Login Page requirements

    master

    When implementing the Login Page in this project, follow these functional and validation rules to ensure consistency with the application's architecture:

    Field Validation & Error Handling

    • Initial State: Fields must start without error messages.
    • Real-time Validation: Validate both email and password as the user types.
    • Error Visibility:
      • Show an error message if the email or password is invalid.
      • Remove the error message immediately once the field becomes valid.
      • Error messages should only disappear if the field meets the validation criteria.

    Button Logic

    • Initial State: The login button must start in a disabled state.
    • Dynamic State:
      • Enable the login button only if all fields are valid.
      • Disable the login button if any field is invalid.

    Login Action Lifecycle

    1. Start: Display a loading indicator at the beginning of the login action.
    2. Execution: Call the authentication method.
    3. Failure: If authentication fails, display an error message.
    4. End: Hide the loading indicator once the action completes.
    • Clicking the 'Create Account' link must trigger the method to navigate to the account creation flow.