Where does 99% of your Flutter code go?
The lib/ folder contains all your Dart source code. Platform folders are auto-generated and rarely touched.
Understand how a Flutter project is organized
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
When you run flutter create my_app, Flutter generates a complete project with several folders and files. Let us go through each part so you understand what everything does.
1my_flutter_app/2├── lib/ → YOUR DART CODE LIVES HERE (99% of your work)3│ └── main.dart → App entry point4├── android/ → Android-specific config (auto-generated)5├── ios/ → iOS-specific config (auto-generated)6├── web/ → Web-specific files (index.html, etc.)7├── windows/ → Windows desktop config8├── macos/ → macOS desktop config9├── linux/ → Linux desktop config10├── test/ → Your test files11├── pubspec.yaml → Dependencies & project config12├── pubspec.lock → Locked dependency versions13├── analysis_options.yaml → Linting rules14└── README.md → Project documentation
As a beginner, you will spend almost all of your time in the lib/ folder. That is where your Dart code lives. The platform folders like android/, ios/, and web/ are auto-generated by Flutter and you rarely need to edit them directly.
Everything you write in Flutter goes inside the lib/ folder. As your app grows, it is a good practice to organize your code into subfolders like this:
lib/
├── main.dart ← Entry point (runApp lives here)
├── app.dart ← Root MaterialApp widget
├── screens/ ← Full-page UIs (HomeScreen, LoginScreen)
│ ├── home_screen.dart
│ └── login_screen.dart
├── widgets/ ← Reusable UI components
│ ├── custom_button.dart
│ └── user_card.dart
├── models/ ← Data classes (User, Product)
│ └── user.dart
├── services/ ← Business logic (API calls, database)
│ └── api_service.dart
└── utils/ ← Helper functions & constants
└── constants.dart
This structure keeps your code organized and easy to navigate as your app grows. You do not have to create all these folders right away. Start simple and add folders as your project gets bigger.
This is the most important configuration file in your Flutter project. It defines your app name, version, dependencies, and assets. If you have used package.json in Node.js, pubspec.yaml serves a similar purpose.
1name: my_flutter_app # Your app's name2description: A new Flutter project3version: 1.0.0+1 # version + build number45# Dart SDK version constraint6environment:7sdk: '>=3.0.0 <4.0.0'89# Your app's packages (libraries)10dependencies:11flutter:12sdk: flutter # Flutter itself13http: ^1.1.0 # For making API calls14provider: ^6.0.0 # State management15shared_preferences: ^2.2.0 # Local storage1617# Dev-only packages (not in final app)18dev_dependencies:19flutter_test:20sdk: flutter21flutter_lints: ^3.0.0 # Code quality rules2223# Flutter-specific settings24flutter:25uses-material-design: true # Enable Material icons26assets: # Declare image/file assets27- assets/images/28- assets/icons/29fonts: # Custom fonts30- family: Roboto31fonts:32- asset: assets/fonts/Roboto-Regular.ttf
To add a new package to your project, you can either edit pubspec.yaml manually and run flutter pub get, or use the command flutter pub add package_name which does both steps for you automatically.
Every Flutter app starts from the main() function inside lib/main.dart. This is where you tell Flutter which widget to display first.
1// Import Flutter's Material Design library2import 'package:flutter/material.dart';34// main() is where every Dart program starts5void main() {6// runApp() inflates the given widget and attaches it7// to the screen. This is the root of your widget tree.8runApp(const MyApp());9}1011// MyApp is your root widget12class MyApp extends StatelessWidget {13const MyApp({super.key});1415@override16Widget build(BuildContext context) {17return MaterialApp(18title: 'My App', // App name in task manager19debugShowCheckedModeBanner: false, // Remove debug banner20theme: ThemeData( // App-wide theme21primarySwatch: Colors.blue,22useMaterial3: true, // Use Material 3 design23),24home: const HomeScreen(), // First screen to show25);26}27}
| File | Purpose | Edit Often? |
|---|---|---|
| lib/main.dart | App entry point | Yes |
| pubspec.yaml | Dependencies and configuration | Often |
| analysis_options.yaml | Linting rules | Rarely |
| android/app/build.gradle | Android build config | Sometimes |
| ios/Runner/Info.plist | iOS app config | Sometimes |
| web/index.html | Web page template | Rarely |
As you can see, the two files you will interact with most often are main.dart and pubspec.yaml. The rest are either auto-generated or only need changes for specific platform configurations.
Avoid creating a huge folder structure on day one. Grow structure with app complexity:
This incremental approach keeps beginners productive while still preparing for scale.
Organize by feature when the app grows, not by personal preference alone. Team readability is more important than perfect folder aesthetics.
Understand how a Flutter project is organized. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Build confidence with basics first; speed comes later.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
The lib/ folder contains all your Dart source code. Platform folders are auto-generated and rarely touched.
Every Dart program starts from the main() function. In Flutter, main() typically calls runApp() with your root widget.
pubspec.yaml is Flutter's package manifest: similar to package.json in Node.js or build.gradle in Android.
flutter pub get downloads and caches all packages listed in your pubspec.yaml file.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue