Flutter Project Structure
A new Flutter project creates dozens of files and folders. Knowing the purpose of each one saves hours of confusion later. Picture the project as a house: some rooms hold the furniture you choose (your code), and other rooms hold the plumbing and wiring (the tools that build the app for each device).
The Folder Map
Run flutter create my_app and Flutter generates this layout:
my_app/
├── lib/ ← YOUR code lives here
│ └── main.dart ← the app starts here
├── test/ ← automated tests
│ └── widget_test.dart
├── android/ ← Android build files
├── ios/ ← iPhone and iPad build files
├── web/ ← browser build files
├── windows/ macos/ linux/ ← desktop build files
├── pubspec.yaml ← project settings and packages
├── pubspec.lock ← exact package versions
└── analysis_options.yaml ← code style rules
The lib Folder
Almost all of your work happens inside lib. The file main.dart holds the main() function, the entry point of every Flutter app. Dart runs this function the moment the app opens.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
The runApp call hands the root widget to Flutter. Flutter draws that widget and everything inside it.
The pubspec.yaml File
Think of pubspec.yaml as the shopping list and ID card of your app. It stores the app name, the version number, the Dart version range, the packages the app needs, and the assets such as images and fonts.
name: my_app
description: A simple learning app.
version: 1.0.0+1
environment:
sdk: ^3.0.0
dependencies:
flutter:
sdk: flutter
flutter:
assets:
- assets/images/
Indentation Matters
YAML files use spaces to show structure. Two spaces mark a child item. A wrong number of spaces breaks the file and produces an error when you run flutter pub get.
Adding a Package
Run flutter pub add package_name in the terminal. Flutter writes the package into dependencies and downloads it automatically.
Platform Folders
Each platform folder contains a native project that wraps your Dart code. Flutter fills these folders for you, and most beginners never open them. You visit them when you change the app icon, the app name shown on the phone, or the permissions the app requests.
| Folder | Common Reason to Open It |
|---|---|
| android | Set permissions in AndroidManifest.xml |
| ios | Set permission messages in Info.plist |
| web | Edit the page title and icon in index.html |
Files and Folders to Leave Alone
build/holds compiled output. Flutter recreates it on every build..dart_tool/stores tool data. Version control ignores it.pubspec.lockrecords exact package versions. Flutter updates it automatically..metadatatracks the Flutter version that created the project.
A Clean Structure for Growing Apps
One file works for a tiny demo. A real app needs folders that separate responsibilities. Each folder answers one question: what does the app show, what data does it use, and how does it talk to the outside world?
lib/
├── main.dart
├── models/ ← data shapes (User, Product)
├── screens/ ← full pages (HomeScreen, LoginScreen)
├── widgets/ ← small reusable pieces (ProductCard)
├── services/ ← network and storage code
└── utils/ ← helpers and constants
Naming Rules
Dart file names use lowercase letters with underscores, such as login_screen.dart. Class names use capital letters for each word, such as LoginScreen. Following these rules makes your code look familiar to every Flutter developer.
Importing Your Own Files
Use the package name and the path inside lib to import a file:
import 'package:my_app/screens/home_screen.dart';
This style stays valid when you move files around, because it never depends on the location of the importing file.
Practice Ideas
Create a new project and open every top-level folder. Add a screens folder with a file named home_screen.dart, then import it into main.dart. Add one image under an assets folder, register it in pubspec.yaml, and display it with Image.asset. Each step proves how the pieces connect.
