Flutter Project Structure
flutter create generates a lot of files. Most of them you will rarely touch, but knowing what each folder is for helps you find your way around any Flutter project.
The top-level layout
flutter create notes_app
cd notes_app
lsREADME.md analysis_options.yaml android ios lib linux macos notes_app.iml pubspec.lock pubspec.yaml test web windows
| Path | Purpose |
|---|---|
lib/ |
Your Dart code. lib/main.dart contains main(), the app's entry point |
test/ |
Unit and widget tests, run with flutter test |
pubspec.yaml |
Project name, version, SDK constraint, dependencies and assets |
pubspec.lock |
Exact package versions that were resolved (commit it for apps) |
analysis_options.yaml |
Lint rules used by the analyzer and your editor |
android/, ios/ |
Native host projects for mobile (app icon, permissions, signing) |
web/, windows/, macos/, linux/ |
Native host projects for the other platforms |
build/ |
Generated build output — never edit or commit it |
.dart_tool/ |
Tool caches — also generated |
Tip: As a beginner, spend 99% of your time in
lib/,test/andpubspec.yaml. Open the platform folders only when you need to change an app icon, permission or bundle ID.
pubspec.yaml
This YAML file describes your package. Indentation matters — use two spaces.
name: notes_app
description: "A simple notes app."
publish_to: 'none'
version: 1.0.0+1 # versionName+buildNumber
environment:
sdk: ^3.5.0
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
http: ^1.2.2 # added with: flutter pub add http
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^4.0.0
flutter:
uses-material-design: true
assets:
- assets/images/- dependencies are packages your app needs at runtime, downloaded from pub.dev.
- dev_dependencies are only used during development (tests, lints, code generators).
- The flutter → assets list registers images, fonts and data files bundled with the app.
Adding a package from the command line edits pubspec.yaml and downloads it for you:
flutter pub add httpResolving dependencies...
Downloading packages...
+ http 1.2.2
+ http_parser 4.0.2
Changed 2 dependencies!
Organising lib/
A brand-new project has a single lib/main.dart. As the app grows, split it into files and folders. A common layout:
lib/
main.dart // runApp + MaterialApp
models/
note.dart // plain Dart classes
screens/
home_screen.dart
edit_screen.dart
widgets/
note_tile.dart // small reusable widgets
services/
note_storage.dart // HTTP, database, filesFiles import each other with package: imports, which start from lib/:
// lib/main.dart
import 'package:flutter/material.dart';
import 'package:notes_app/screens/home_screen.dart';
void main() => runApp(const NotesApp());
class NotesApp extends StatelessWidget {
const NotesApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Notes',
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
// lib/screens/home_screen.dart
// import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Notes')),
body: const Center(child: Text('No notes yet')),
);
}
}Setting debugShowCheckedModeBanner: false hides the red "DEBUG" ribbon in the corner during development.
The test folder
The starter project includes test/widget_test.dart, which pumps the counter app and taps the "+" button. Running it:
flutter test00:03 +1: All tests passed!
You will write your own tests in the Testing lesson.
Test yourself
Where does the Dart code of your app live?
- src/
- lib/
- app/
- android/
Which file lists the packages your app depends on?
- package.json
- pubspec.lock
- pubspec.yaml
- analysis_options.yaml
Where should packages used only for testing go?
- dependencies
- dev_dependencies
- flutter: assets
- environment