Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Development Environment  ›  Lesson

The Flutter CLI

Flutter CLI 12 minThe flutter command checks your setup with doctor, scaffolds projects with create, and launches them with run, where hot reload keeps app state and hot restart resets it.

The Flutter CLI

Sprout is ready to leave DartPad and become a real project on your machine. Everything you do from here, whether you click buttons in an editor or not, is driven by one program: the flutter command. Knowing its handful of everyday subcommands makes every editor feel familiar.

The rule

doctor checks, create scaffolds, run launches, r reloads.

flutter doctor          # checks the SDK, platforms and devices
flutter create sprout   # makes a new project folder called sprout
cd sprout
flutter devices         # lists phones, emulators, browsers and desktops
flutter run             # builds and starts the app on a device
  • flutter doctor prints a checklist. A cross next to Android or Xcode tells you exactly what to install before that platform will work.
  • flutter create needs a valid Dart package name: lower-case letters, digits and underscores, like sprout or plant_pal.
  • flutter run stays open after launching. While it runs, keys typed in the terminal control the app:
Key What it does
r Hot reload: inject changed code, rebuild widgets, keep state
R Hot restart: rerun main() from scratch, state is lost
q Quit the app

The shortcut

Before pressing a key, ask "Did I change what the app looks like, or how it starts?"

Changing Sprout while it runsStep 1 of 4
  1. Change a label in a build method

    You edit the text of the "Water now" button. That is how the app looks, so press r. The plants already on screen stay put.

The trap is thinking hot reload "did not work". Usually the change was in code that only runs at start-up, such as main() or a state's initState, so it needs a restart.

Drills

Answer fast — trust the rule.

quick drill

Which command lists missing tools such as the Android SDK?

quick drill

Which is a valid name for flutter create?

quick drill

You press r after editing a widget's colour. What happens to the plants you added in the running app?

quick drill

You changed the list that main() builds. Which key shows the change?

Remember

  • doctor checks, create scaffolds, run launches, r reloads.
  • Looks changed? r. Start-up changed? R. Native code changed? run again.
  • Trap: hot reload never reruns main() or initState.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainReload or restart?

You have Sprout running with three plants added in memory. You change a button's colour, and later you change the starting list of plants that main() builds. For each change, say whether hot reload is enough or you need a hot restart, and explain why.