# Setting Up and Hot Reload — Flutter

Source: https://www.skillbyai.com/en/flutter/f-setup

> flutter create, flutter doctor and the edit loop.

## The Flutter CLI

After installing the Flutter SDK (which bundles Dart), `flutter doctor` checks your toolchain: Android SDK, Xcode on macOS, connected devices and IDE plugins. `flutter create my_app` scaffolds a project with `lib/main.dart`, a `pubspec.yaml` for dependencies and assets, and platform folders such as `android/` and `ios/`. `flutter run` builds and launches on a device or emulator in **debug mode**. While it runs, **hot reload** (press `r`) injects changed code into the running Dart VM and rebuilds widgets while keeping state; **hot restart** (`R`) restarts the app and resets state. Changes to `main()`, global initialisers or native code need a restart or full rebuild.

## Everyday commands

Create, check, run and add a package.

```bash
flutter doctor            # verify SDKs, devices and IDE setup
flutter create my_app     # scaffold a new project
cd my_app
flutter devices           # list connected devices and emulators
flutter run               # build and run in debug mode (r = hot reload, R = hot restart)
flutter pub add http      # add a dependency to pubspec.yaml
flutter pub get           # fetch dependencies
flutter analyze           # static analysis using analysis_options.yaml
```

## Know which reload you need

If a change does not appear after hot reload, it usually touched state initialisation (initState, field initialisers, main) - use hot restart before suspecting a bug.

**Quiz:** What is the key difference between hot reload and hot restart?

- [x] Hot reload keeps app state; hot restart resets it
- [ ] Hot reload recompiles native Android and iOS code
- [ ] Hot restart only works in release mode
- [ ] There is no difference

*Answer:* Hot reload keeps app state; hot restart resets it. Hot reload patches code into the running VM and rebuilds; hot restart starts the Dart app again.
