Step-by-Step Guide to Flutter Folder Structure for Better Organization

For a large-scale Flutter project, maintaining a clean, scalable, and organized folder structure is crucial. Here's a recommended folder structure that keeps everything modular and easy to manage. Hi this is Softradix Technologies a flutter app development company in USA. Today we are going to share our practical experience of best flutter folder structure.

Top-Level Structure

/lib
├── core/
├── features/
├── config/
├── common/
├── data/
├── domain/
├── presentation/
├── services/
├── utils/
├── main.dart

Explanation of Each Folder

  1. core/
    This folder holds core functionality and utilities that are shared across the app.

    • Purpose: To provide global services, constants, themes, and configuration utilities.

    • Subfolders:

      • constants/: Global constants and static values (e.g., API endpoints, themes).

      • themes/: Global theme settings like ThemeData for light/dark modes.

      • error/: Error handling classes and utilities.

      • routes/: App routing and navigation structure.

Example:

/lib/core
├── constants/
├── themes/
├── error/
└── routes/
  1. features/
    Divide the app by features to maintain modularity, where each feature gets its own directory.
  • Purpose: Each feature will have its own directory, and inside it, you'll store feature-specific presentation, domain, and data layers.

  • Subfolders (per feature):

    • presentation/: All UI-related code like widgets, screens.

    • data/: Models, repositories, and data sources.

    • domain/: Business logic like use cases and entities.

Example:

/lib/features
├── auth/
│   ├── presentation/
│   ├── data/
│   └── domain/
├── profile/
└── dashboard/
  1. config/
    Global configuration files such as environment settings, API configurations, and other setup files.
  • Purpose: Centralized configuration that is shared across the app.

Example:

/lib/config
├── api_config.dart
└── env.dart
  1. common/
    Reusable components that are used across different features.
  • Purpose: To hold shared widgets, styles, or utilities that don't belong to a single feature.

Example:

/lib/common
├── widgets/
├── styles/
└── dialogs/
  1. data/
    Manages the data layer, responsible for fetching and storing data (APIs, local storage).
  • Subfolders:

    • models/: Data models for your app.

    • repositories/: Abstracted repositories that interact with data sources (remote/local).

    • data_sources/: API, database, or other data sources.

Example:

/lib/data
├── models/
├── repositories/
└── data_sources/
  1. domain/
    Contains business logic like entities, use cases, and repository interfaces.
  • Subfolders:

    • entities/: Core business models/entities.

    • use_cases/: Classes that contain the business logic of the app.

Example:

/lib/domain
├── entities/
└── use_cases/
  1. presentation/
    Handles all UI-related code, such as widgets, screens, and state management.
  • Subfolders:

    • screens/: Individual screens.

    • widgets/: Reusable UI components.

    • state/: State management (e.g., Bloc, Cubit, Provider).

Example:

/lib/presentation
├── screens/
├── widgets/
└── state/
  1. services/
    This directory contains application services such as authentication, notifications, etc.
  • Purpose: Handles non-UI services that interact with APIs, authentication, push notifications, etc.

Example:

/lib/services
├── authentication_service.dart
└── notification_service.dart
  1. utils/
    Contains utility functions and helper classes (e.g., formatting, validation, extensions).
  • Purpose: Shared utility functions that help across the application.

Example:

/lib/utils
├── formatters.dart
└── validators.dart

Example Structure for a Huge Flutter Project

/lib
├── core
│   ├── constants/
│   ├── themes/
│   ├── error/
│   └── routes/
├── features
│   ├── auth/
│   │   ├── presentation/
│   │   ├── data/
│   │   └── domain/
│   ├── profile/
│   └── dashboard/
├── config/
├── common
│   ├── widgets/
│   ├── styles/
│   └── dialogs/
├── data
│   ├── models/
│   ├── repositories/
│   └── data_sources/
├── domain
│   ├── entities/
│   └── use_cases/
├── presentation
│   ├── screens/
│   ├── widgets/
│   └── state/
├── services
├── utils
└── main.dart

Benefits of This Structure

  • Scalability: It’s easy to add new features, modules, or services without restructuring the entire project.

  • Modularity: Each feature has its own directory with presentation, domain, and data layers, making it easy to manage and maintain.

  • Separation of Concerns: Clear separation between the data layer, domain logic, and presentation ensures cleaner code and easier testing.

  • Reusability: Shared components, services, and utilities are centralized for reuse across the app.

This structure keeps things modular and organized, which is especially important for large, complex projects. Let me know if you'd like to dive into any specific folder or approach!

0
Subscribe to my newsletter

Read articles from Softradix Technology directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Softradix Technology
Softradix Technology

SoftRadix is your go-to partner for innovative solutions. our services include web design, mobile app development, the best and most affordable angular development agency in the USA, and strategic digital marketing. As a trusted name in the industry, we prioritize quality, affordability, and customer success. Whether you’re a startup, a small business, or an enterprise, SoftRadix offers reliable and customized solutions to help you thrive in the digital landscape. Trust us to transform your ideas into reality!