Skip to content

castroreyrobert/article_hub

Repository files navigation

Article Hub

Flutter Logo Dart Logo GitHub last commit License

A concise description of your Flutter application. This project demonstrates a robust, scalable, and maintainable Flutter application built with Clean Architecture, powered by BLoC for state management, and utilizing Retrofit with Dio for efficient and type-safe network operations.

✨ Features

  • User Authentication: Secure login and signup flows.

  • Article Management: View a list of articles and their detailed content.

  • Data Persistence: User session management (e.g., login token persistence).

  • Responsive UI: Adapts to various screen sizes and orientations.

  • (Add more specific features of your app here, e.g., CRUD operations for articles, search, etc.)

🚀 Technologies Used

This project leverages modern Flutter and Dart best practices and a powerful set of libraries:

  • Flutter SDK: The core framework for building beautiful, natively compiled applications from a single codebase.

  • BLoC (Business Logic Component): For robust and predictable state management.

    • flutter_bloc: Official Flutter integration for BLoC.

    • equatable: For simplifying equality comparisons in Dart objects.

  • Network Layer:

    • dio: A powerful HTTP client for Dart, supporting interceptors, global configuration, etc.

    • retrofit: A type-safe HTTP client generator for Dart, inspired by Retrofit for Java/Kotlin. It uses dio under the hood.

    • json_annotation & json_serializable: For automated JSON serialization/deserialization, ensuring type-safe data models.

    • build_runner: The build tool used to generate code for json_serializable and retrofit.

  • Dependency Injection / Service Locator:

    • get_it: A simple and fast service locator to register and retrieve service objects.
  • Local Storage:

    • shared_preferences: For light-weight, persistent key-value storage (e.g., storing authentication tokens).
  • (Add any other significant packages you use, e.g., go_router, freezed, etc.)

🏗️ Architecture: Clean Architecture

The project adheres to the principles of Clean Architecture to achieve separation of concerns, testability, and maintainability. It is structured into distinct layers:

  • Presentation Layer (screens/, widgets/):

    • Handles UI rendering and user interactions.

    • Interacts with the Application/Domain layer (BLoC) to send events and listen for state changes.

    • Does not contain business logic.

  • Application/Domain Layer (blocs/, usecases/, entities/):

    • Contains the core business logic of the application.

    • BLoCs manage the state and react to events, orchestrating interactions between the UI and data layer.

    • Use Cases define specific business operations.

    • Entities represent the core business objects.

  • Data Layer (repositories/, datasources/, models/):

    • Responsible for fetching data from various sources (APIs, local database, shared_preferences).

    • Repositories define abstract interfaces for data operations.

    • Data Sources implement these interfaces for specific data sources (e.g., RemoteDataSource for API, LocalDataSource for local storage).

    • Data models (models/) define the structure of data received from external sources.

📦 State Management: BLoC

BLoC (Business Logic Component) is used to manage application state. Each feature or complex screen typically has its own BLoC, which:

  • Receives Events (user actions, data updates).

  • Processes these events using business logic.

  • Emits new States that the UI reacts to and rebuilds accordingly.

This pattern ensures a unidirectional data flow, making the application's state predictable and testable.

🌐 Network Layer: Retrofit & Dio

The project utilizes a powerful combination for network operations:

  • Dio: The underlying HTTP client handles the actual network requests, interceptors (for adding auth headers, logging), error handling, and more.

  • Retrofit: A code generator that builds type-safe API clients from Dart interfaces. You define your API endpoints, request methods, and expected responses using annotations, and Retrofit generates the boilerplate code for you. This significantly reduces manual work and improves code readability and safety.

Example structure:


// api\_client.dart (Retrofit interface)
@RestApi(baseUrl: "[https://reqres.in/api/](https://www.google.com/search?q=https://reqres.in/api/)")
abstract class AuthApiClient {
factory AuthApiClient(Dio dio, {String baseUrl}) = \_AuthApiClient;

@POST("/login")
Future\<UserResponse\> login(@Body() Map\<String, dynamic\> body);
}

⚙️ Installation

To get this project up and running on your local machine, follow these steps:

  1. Clone the repository:

git clone [https://github.com/YOUR\_USERNAME/YOUR\_REPO\_NAME.git](https://www.google.com/search?q=https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git)
cd YOUR\_REPO\_NAME

  1. Install Flutter dependencies:

flutter pub get

  1. Generate code for data models and API clients: This step is crucial for json_serializable and retrofit.

flutter pub run build\_runner build --delete-conflicting-outputs

If you modify your data models or Retrofit service interfaces, you'll need to run this command again.

  1. Run the application: Connect a device or start an emulator/simulator.

flutter run

📂 Project Structure


lib/
├── config/             \# Global configurations, constants
├── data/               \# Data Layer: Repositories, Data Sources
│   ├── datasources/    \# Remote (API), Local (SharedPreferences)
│   └── repositories/   \# Interfaces and implementations for data operations
├── domain/             \# Application/Domain Layer: Entities, Use Cases
│   ├── entities/       \# Core business objects
│   └── usecases/       \# Business logic operations
├── presentation/       \# Presentation Layer: UI (Screens, Widgets), BLoCs
│   ├── auth/           \# Authentication related BLoCs and screens
│   │   ├── bloc/
│   │   └── screens/
│   ├── articles/       \# Article related BLoCs and screens
│   │   ├── bloc/
│   │   └── screens/
│   └── widgets/        \# Reusable UI components
├── services/           \# External service wrappers (e.g., ApiClient, LocalStorageService)
├── main.dart           \# Application entry point
└── app.dart            \# Top-level widget, global providers/setup

🤝 Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

  1. Fork the repository.

  2. Create a new branch: git checkout -b feature/your-feature-name

  3. Make your changes and commit them: git commit -m 'feat: Add new feature'

  4. Push to the branch: git push origin feature/your-feature-name

  5. Open a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published