Beginner · Flutter setup and your first app · topic 14 of 50 · 30 min
Project structure and hot reload
Explanation
Creating a project
flutter create chai_shop
cd chai_shop
flutter runWhat is inside
chai_shop/
├── lib/
│ └── main.dart <- your app starts here (main function)
├── test/
│ └── widget_test.dart <- tests (module 10)
├── android/ ios/ web/ windows/ macos/ linux/ <- platform projects
├── assets/ <- images, fonts (you create it and list it in pubspec)
├── pubspec.yaml <- name, version, packages, assets
├── pubspec.lock <- exact package versions
└── analysis_options.yaml <- lint rules for code qualityThe platform folders are real native projects. android/ is a normal Android Gradle project; ios/ is an Xcode project. Flutter generates them and you rarely edit them, except for things like the app name, permissions in AndroidManifest.xml or Info.plist, and signing for release (module 11).
The starter main.dart in brief
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp()); // put the root widget on the screen
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Chai Shop',
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.brown)),
home: const Scaffold(
body: Center(child: Text('Namaste from Chai Shop')),
),
);
}
}Hot reload, hot restart, full restart
| Action | How | What happens | State kept? |
|---|---|---|---|
| Hot reload | Press r in the terminal, or save in VS Code/Android Studio | New code is injected and build methods re-run | Yes |
| Hot restart | Press R | Dart code restarts from main() | No, state resets |
| Full restart | Stop and flutter run again | Native app rebuilt and reinstalled | No |
Hot reload is Flutter's superpower: you change a colour, a padding or some text and see it on the phone in about a second, still on the same screen with the same data. Some changes are not picked up by hot reload, such as changes to main(), to initState of a widget that already exists, to global variables' initial values, or to native code and pubspec packages. If a change "does not show", try hot restart, and for native or package changes, a full restart.
DevTools
Flutter DevTools is a set of debugging tools that opens in the browser or inside your editor: the widget inspector (see the widget tree and layout), a performance view, a memory view, network and logging views. You will use it in module 9; open it once now from your editor to see your app's widget tree.
Common mistakes
- Expecting hot reload to apply changes to main() or initState: use hot restart.
- Adding a package and only hot reloading: stop and run again after pub get adds native code.
- Editing generated files in build/: they are overwritten.
- Deleting platform folders you do not think you need; recreate them with flutter create . if needed.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Project structure and hot reload · 1/6
flutter create makes a project. flutter run starts it on a device.
Prefer a video by a teacher? Find free videos on “flutter project structure hot reload vs hot restart explained” on YouTube ↗
In real life: Designing a menu screen with a shop owner
A freelance developer sits with a restaurant owner to design the menu screen. With the app running on the owner's phone, every request ("bigger prices", "green instead of red", "move the photo left") is a quick edit and save; hot reload shows the result in a second, still on the same screen. The design is finished in one meeting instead of a week of screenshots over WhatsApp.
Practice (0/3 done)
You changed the initial value of a counter in initState and hot reloaded, but nothing changed. What should you do?
Where does the code you write mostly live in a Flutter project?
Create a project with flutter create, run it on a device, change the text and theme colour and hot reload. Then add a counter value, change its starting number and notice that hot reload keeps the old value while hot restart resets it. Open DevTools and find your Text widget in the widget inspector.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Everything is a widgetFlutter setup and your first app · same module
- Stateless and stateful widgetsFlutter setup and your first app · same module
- Interview questions: FlutterFlutter careers and interviews
- Preparing a releasePublishing to the stores and the web
- Images, icons, fonts and themesLayouts
- Control flow and collectionsDart basics
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What does hot reload keep?
Answer: The app's current state
That is what makes it fast for UI work.
Which key triggers hot restart in the flutter run terminal?
Answer: R
Lowercase r is hot reload; capital R is hot restart.
What is analysis_options.yaml for?
Answer: Lint rules and static analysis settings
It configures the analyser.
What does runApp do?
Answer: Puts the root widget on the screen
It starts the widget tree.
What makes hot reload possible during development?Related
Answer: Dart's JIT compilation in debug mode
JIT lets code be swapped into the running app.
Which needs a hot restart rather than a hot reload?Related
Answer: Changing the initial value set in initState of an existing widget
initState does not run again on reload.
Which command downloads the packages listed in pubspec.yaml?Related
Does the Flutter SDK include Dart?Related
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Flutter setup and your first app” before its exam: Everything is a widget, Stateless and stateful widgets.
- Module 4 exam: Flutter setup and your first app · 12 questions · 20 min, without help. 4 topics of this module still to finish first.
- Then the next module, Layouts. 50 topics left in the course before the final exam.