Skip to content

ismailelmogy/flutter-tdd-clean-architecture-course

 
 

Repository files navigation

TDD Clean Architecture for Flutter

Number Trivia App

Number Trivia App

Number Trivia App using clean architecture and test-driven development
Project inspired by Reso Coder's Clean Architecture TDD Course.

What's Included

  • State Management using the BLoC pattern
  • Test-Driven Development with unit tests for domain and data layers using mocktail
  • Dependency Injection using get_it
  • Functional Programming with dartz package
  • Equality Checks in classes using equatable
  • REST API integration with http
  • Exception Handling using custom Failure classes
  • Persistent Data using shared preferences
  • Null Safety support for safer, more reliable code

Project Architecture

This project follows the principles of Clean Architecture. The code is split into the following layers:

  • Domain Layer: Contains core business logic and use cases.
  • Data Layer: Handles data from APIs, local databases, or any external sources.
  • Presentation Layer: Manages the user interface (UI) using BLoC for state management.

Clean Architecture Diagrams

  • Reso Coder's Clean Architecture Diagram
    Reso Coder's Clean Architecture

  • Robert C. Martin's Clean Architecture Diagram
    Robert C. Martin's Clean Architecture

By using this structure, it's easier to test, modify, and extend the application, especially in large-scale projects.

Key Features

1. Bloc State Management

Bloc (Business Logic Component) is used for managing states across the app. This makes the app's business logic independent of the UI.

2. Dependency Injection

The get_it package is used for easy dependency injection, making it simple to switch implementations or mock objects for testing.

3. Functional Programming with Dartz

The dartz package enables functional programming patterns, such as using Either for handling failures and successes, ensuring clean and maintainable code.

4. API Integration

The app uses the http package for fetching data from a REST API. It retrieves [describe the data, e.g., trivia, user information].

5. Error Handling

Custom Failure classes handle exceptions gracefully, ensuring a smooth user experience when errors occur.

6. Null Safety

This project is built with Dart's Null Safety features enabled, ensuring fewer runtime errors and safer code by handling null values properly.

Testing

This project follows Test-Driven Development (TDD) practices. Unit tests are provided for the domain, data, and presentation layers. To run the tests, use:

flutter test

We use the mocktail package for mocking dependencies in the tests. This ensures clean and isolated testing of components by mocking external dependencies such as services and repositories.

How to Contribute

Feel free to contribute to this project. You can do so by:

  1. Forking the repository.
  2. Creating a feature branch (git checkout -b feature/your-feature).
  3. Committing your changes (git commit -m 'Add some feature').
  4. Pushing to the branch (git push origin feature/your-feature).
  5. Opening a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


More tutorials and information on Flutter development can be found on Reso Coder.


This updated README includes information about:

  • The use of mocktail for testing.
  • Support for Null Safety, highlighting that the project uses Dart’s safety features to avoid null reference errors.

If you'd like to add more details, like specific features or screenshots, feel free to reach out!

Releases

No releases published

Packages

No packages published

Languages

  • Dart 57.4%
  • C++ 19.8%
  • CMake 16.2%
  • Ruby 2.3%
  • Swift 1.5%
  • C 1.2%
  • Other 1.6%