Files in your Flutter Project
In a Flutter project, the files are organized so that your Dart application code, UI resources, platform-specific Android/iOS code, dependencies, and build configuration remain separated.
A typical project looks like this:
1. lib/ ⭐ Most important
This is where almost all of your Flutter application code lives.
For most day-to-day Flutter development, you spend the majority of your time here.
main.dart
The entry point of the Flutter application.
A minimal example:
Execution starts with:
which normally calls:
to start the Flutter widget tree.
2. pubspec.yaml ⭐ Very important
Think of this as the configuration/manifest file of your Flutter project.
It defines things such as:
- Project name
- Version
- Dart/SDK constraints
- Flutter dependencies
- Third-party packages
- Fonts
- Images and other assets
Example:
If you want to use a package such as:
you would normally declare http under dependencies.
After changing dependencies, you typically run:
3. pubspec.lock
Records the exact versions of packages resolved for your project.
For example, pubspec.yaml might allow a compatible range, while pubspec.lock records the particular version selected.
Conceptually:
For Flutter applications, this file is normally committed to Git so developers and CI use consistent resolved versions.
4. android/
Contains the native Android project used to package and run your Flutter application on Android.
Typical contents include:
You usually modify this directory when dealing with things like:
- Android permissions
- Native Android integrations
- Gradle configuration
- App signing
- Android-specific SDK configuration
- Package/application settings
For example, Android permissions are configured through:
You might add internet or other native permissions there.
5. ios/
The equivalent native project for iPhone/iPad.
Used when configuring things such as:
- iOS permissions
- Apple signing
- Bundle identifiers
- CocoaPods
- Native Swift/Objective-C integration
- iOS-specific settings
For example:
contains many iOS application configuration values.
6. web/
Contains Flutter Web-specific files.
Common files include:
index.html
Acts as the HTML host/bootstrap page for the Flutter web application.
manifest.json
Contains metadata relevant to the web app/PWA experience, such as name, icons, and display behavior.
7. windows/
Native Windows desktop application wrapper/configuration.
Usually contains C++ and build configuration associated with running your Flutter UI as a Windows application.
You generally touch this folder only when you need Windows-specific functionality or configuration.
8. macos/
Native macOS application project.
Similar to ios/, it contains Apple-specific runner and Xcode configuration for building your Flutter application for macOS.
9. linux/
Contains the native Linux runner and build configuration.
You'll primarily interact with it when implementing Linux-specific functionality or customizing the application's native Linux integration.
10. test/
Contains automated Dart/Flutter tests.
For example:
A simple widget test may look like:
As your application grows, you might organize it as:
11. analysis_options.yaml
Configures the Dart analyzer and linting rules.
For example, it can help enforce coding standards and flag issues while you develop.
Think of it as:
"Rules for checking the quality and consistency of my Dart code."
12. .gitignore
Tells Git which generated/local files should not be committed.
Typical examples include build artifacts and IDE-specific files.
13. .dart_tool/
An automatically generated directory used internally by Dart and Flutter tooling.
It can contain:
- Package configuration
- Build information
- Tool metadata
Normally:
Don't manually modify this folder.
14. build/
Contains generated build output.
Flutter creates it when compiling/building the application.
For example:
or
will generate build artifacts.
You normally do not manually edit anything inside build/.
A real application's lib folder
The default Flutter project is intentionally simple. For your own application, the structure might evolve into something like:
The responsibilities could be:
| Folder | Purpose |
|---|---|
models/ | Data/domain objects such as User, SalesOrder, Customer |
screens/ | Complete application pages |
widgets/ | Reusable UI components |
services/ | APIs, databases, authentication, etc. |
providers/ | Application/state-management logic when using Provider |
utils/ | Common utilities, constants, validators |
For example, if you were building an ERP-style Flutter application, you could structure a Sales Order feature as:
The basic flow becomes:
main.dart → Screen → Widget → Service/API → Model → UI
That separation becomes increasingly important as your Flutter application grows.
Comments
Post a Comment