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
doctorchecks,createscaffolds,runlaunches,rreloads.
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 deviceflutter doctorprints a checklist. A cross next to Android or Xcode tells you exactly what to install before that platform will work.flutter createneeds a valid Dart package name: lower-case letters, digits and underscores, likesproutorplant_pal.flutter runstays 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?"
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.
Which command lists missing tools such as the Android SDK?
Which is a valid name for flutter create?
You press r after editing a widget's colour. What happens to the plants you added in the running app?
You changed the list that main() builds. Which key shows the change?
Remember
doctorchecks,createscaffolds,runlaunches,rreloads.- Looks changed?
r. Start-up changed?R. Native code changed? run again. - Trap: hot reload never reruns
main()orinitState.
