๐Ÿ’™

Flutter & Dart ํ•ต์‹ฌ ๊ฐœ๋ฐœ ์น˜ํŠธ์‹œํŠธ

OS๋ณ„ SDK ์„ค์น˜๋ถ€ํ„ฐ Android/iOS ํˆด์ฒด์ธ ์„ค์ •, ํ•„์ˆ˜ CLI, ์œ„์ ฏ ์ƒ๋ช…์ฃผ๊ธฐ, ๋ ˆ์ด์•„์›ƒ/์Šคํƒ€์ผ๋ง, ์ƒํƒœ ๊ด€๋ฆฌ(Provider, Riverpod), ๋‚ด๋น„๊ฒŒ์ด์…˜(GoRouter), ๋น„๋™๊ธฐ ํ†ต์‹ , ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฐ ๋นŒ๋“œ ๋ฐฐํฌ๊นŒ์ง€ ๋‹จ๊ณ„๋ณ„ ํ€ต ๋ ˆํผ๋Ÿฐ์Šค

--views
๋‹จ์ˆ˜:
#flutter#dart#mobile#install#setup#cross-platform#widget#state-management#riverpod#bloc#gorouter#android#ios#web์ตœ์ข… ์—…๋ฐ์ดํŠธ: 2026-10-02

1. [Step 1] ์šด์˜์ฒด์ œ๋ณ„ Flutter SDK ์„ค์น˜ & ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •

๐Ÿ’ป ์‹œ์Šคํ…œ ์„ค์น˜ ๋ฐ ์‹คํ–‰ ์š”๊ตฌ์‚ฌ์–‘ (System Requirements)

ํ•ญ๋ชฉ์ตœ์†Œ ์‚ฌ์–‘ (Minimum)๊ถŒ์žฅ ์‚ฌ์–‘ (Recommended)์ฐธ๊ณ  ๋ฐ ๋น„๊ณ 
์šด์˜์ฒด์ œ (OS)Windows 10/11 64-bit, macOS 12+ (iOS ๋นŒ๋“œ ํ•„์ˆ˜), Linux 64-bitmacOS 14+ (Sonoma, Apple Silicon) ๋˜๋Š” Windows 11iOS/macOS ํƒ€๊นƒ ๋นŒ๋“œ๋Š” Mac ํ•˜๋“œ์›จ์–ด ํ•„์ˆ˜
CPU4 ์ฝ”์–ด ์ด์ƒ (Intel i5/i7, AMD Ryzen 5, Apple Silicon M1+)8 ์ฝ”์–ด ์ด์ƒGradle Android ๋นŒ๋“œ ๋ฐ Xcode ์ปดํŒŒ์ผ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ
๋ฉ”๋ชจ๋ฆฌ (RAM)8 GB ์ด์ƒ16 GB ~ 32 GB ์ด์ƒAndroid ์—๋ฎฌ๋ ˆ์ดํ„ฐ + IDE (VS Code/Android Studio) ๋™์‹œ ๊ตฌ๋™
๋””์Šคํฌ (Storage)15 GB ์ด์ƒ์˜ ์—ฌ์œ  ๊ณต๊ฐ„30 GB ~ 60 GB ์ด์ƒ์˜ ๊ณ ์† SSDFlutter SDK(5GB), Android SDK/NDK, Xcode(20GB+)
๋„คํŠธ์›Œํฌ / ๋Ÿฐํƒ€์ž„Flutter 3.x+, Dart 3.x+, Git, JDK 17Android Studio, Xcode (macOS), CocoaPodsํ•˜๋“œ์›จ์–ด ๊ฐ€์ƒํ™” (VT-x / SVM) ํ™œ์„ฑํ™” ํ•„์ˆ˜
# =============================================================
# ๐ŸชŸ Windows ํ™˜๊ฒฝ ์„ค์น˜ (๊ฐ€์žฅ ํ”ํ•œ ๊ถŒํ•œ/๊ฒฝ๋กœ ์‹ค์ˆ˜ ๋ฐฉ์ง€)
# =============================================================
# 1. ์‚ฌ์ „ ํ•„์ˆ˜ ์š”๊ตฌ์‚ฌํ•ญ: Git for Windows ์„ค์น˜ (https://git-scm.com)
# 2. ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€(docs.flutter.dev)์—์„œ flutter_windows_x.x.x-stable.zip ๋‹ค์šด๋กœ๋“œ
# โš ๏ธ ์ฃผ์˜: 'C:\Program Files\' ๊ฐ™์€ ๊ด€๋ฆฌ์ž ๊ถŒํ•œ ํ•„์š” ํด๋”๊ฐ€ ์•„๋‹Œ 'C:\src\flutter' ๋˜๋Š” 'C:\flutter'์— ์••์ถ• ํ•ด์ œ!
# ๋˜๋Š” Git ๋ช…๋ น์–ด๋กœ ์ง์ ‘ ์›ํ•˜๋Š” ์œ„์น˜์— ํด๋ก :
git clone https://github.com/flutter/flutter.git -b stable C:\flutter

# 3. ํ™˜๊ฒฝ ๋ณ€์ˆ˜ (PATH)์— Flutter bin ๊ฒฝ๋กœ ๋“ฑ๋ก:
# [์‹œ์ž‘] -> '์‹œ์Šคํ…œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ํŽธ์ง‘' ๊ฒ€์ƒ‰ -> [ํ™˜๊ฒฝ ๋ณ€์ˆ˜] -> [์‚ฌ์šฉ์ž ๋ณ€์ˆ˜] ๋˜๋Š” [์‹œ์Šคํ…œ ๋ณ€์ˆ˜]์˜ 'Path' ํŽธ์ง‘
# -> '์ƒˆ๋กœ ๋งŒ๋“ค๊ธฐ' -> 'C:\flutter\bin' ์ถ”๊ฐ€ ํ›„ ํ™•์ธ
# (PowerShell ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์œผ๋กœ ํ•œ ์ค„ ์„ค์ • ์‹œ):
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\flutter\bin", [EnvironmentVariableTarget]::User)

# 4. ์ƒˆ ํ„ฐ๋ฏธ๋„(cmd ๋˜๋Š” powershell) ์—ด๊ณ  ํ™•์ธ:
flutter --version

# =============================================================
# ๐ŸŽ macOS ํ™˜๊ฒฝ ์„ค์น˜ (Apple Silicon M1/M2/M3 vs Intel)
# =============================================================
# Homebrew๋ฅผ ํ†ตํ•œ ์ดˆ๊ฐ„ํŽธ ์„ค์น˜ (๊ถŒ์žฅ):
brew install --cask flutter

# ๋˜๋Š” ์ˆ˜๋™ ์••์ถ• ํ•ด์ œ ๋ฐฉ์‹:
# 1. ์•„ํ‚คํ…์ฒ˜์— ๋งž๋Š” zip ๋‹ค์šด๋กœ๋“œ (Apple Silicon: arm64 / Intel: x64)
mkdir -p ~/development
unzip ~/Downloads/flutter_macos_arm64_*.zip -d ~/development/

# 2. ํ™˜๊ฒฝ ๋ณ€์ˆ˜(PATH) ์ถ”๊ฐ€ (~/.zshrc ๋˜๋Š” ~/.bashrc):
echo 'export PATH="$PATH:$HOME/development/flutter/bin"' >> ~/.zshrc
source ~/.zshrc

# 3. ์„ค์น˜ ํ™•์ธ:
flutter --version

# =============================================================
# ๐Ÿง Linux (Ubuntu/Debian) ํ™˜๊ฒฝ ์„ค์น˜
# =============================================================
# Snap์„ ํ†ตํ•œ ์›ํด๋ฆญ ์„ค์น˜:
sudo snap install flutter --classic

2. [Step 2] ๊ฐœ๋ฐœ ํˆด์ฒด์ธ ์„ค์ • & ๋ผ์ด์„ ์Šค ๋™์˜ (Android / iOS / VS Code)

# -------------------------------------------------------------
# ๐Ÿค– 1. Android ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• (Android Studio)
# -------------------------------------------------------------
# 1) Android Studio ๋‹ค์šด๋กœ๋“œ ๋ฐ ์„ค์น˜ (https://developer.android.com/studio)
# 2) Setup Wizard๋ฅผ ํ†ตํ•ด Android SDK, Platform-tools ์ž๋™ ์„ค์น˜ ์ง„ํ–‰
# 3) ๐Ÿ’ก [๋งค์šฐ ์ค‘์š”!]: Command-line Tools ์„ค์น˜ (๋ฏธ์„ค์น˜ ์‹œ doctor ์—๋Ÿฌ ๋ฐœ์ƒ)
#    - Android Studio ์‹คํ–‰ -> [More Actions] ๋˜๋Š” [Settings] -> [Languages & Frameworks]
#    - [Android SDK] -> [SDK Tools] ํƒญ ํด๋ฆญ
#    - 'Android SDK Command-line Tools (latest)' ์ฒดํฌ๋ฐ•์Šค ์„ ํƒ ํ›„ [Apply] ํด๋ฆญํ•˜์—ฌ ์„ค์น˜!

# 4) Android ๋ผ์ด์„ ์Šค ์ „์ฒด ์ผ๊ด„ ์Šน์ธ (ํ„ฐ๋ฏธ๋„์—์„œ ์‹คํ–‰):
flutter doctor --android-licenses
# ํ™”๋ฉด์— ๋ผ์ด์„ ์Šค ๋™์˜ ์งˆ๋ฌธ์ด ๋‚˜์˜ฌ ๋•Œ๋งˆ๋‹ค 'y'๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๋ชจ๋‘ ์Šน์ธ ์™„๋ฃŒ

# -------------------------------------------------------------
# ๐Ÿ 2. iOS ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ• (macOS ํ•„์ˆ˜)
# -------------------------------------------------------------
# 1) Mac App Store์—์„œ 'Xcode' ์ตœ์‹  ๋ฒ„์ „ ์„ค์น˜
# 2) ํ„ฐ๋ฏธ๋„์—์„œ Xcode ๋ช…๋ น์–ด ๋ผ์ธ ๋„๊ตฌ ์—ฐ๊ฒฐ:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch

# 3) CocoaPods (iOS ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋งค๋‹ˆ์ €) ์„ค์น˜:
brew install cocoapods
# ๋˜๋Š”: sudo gem install cocoapods

# -------------------------------------------------------------
# ๐Ÿ’ป 3. ์—๋””ํ„ฐ(VS Code) ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ ์„ค์น˜
# -------------------------------------------------------------
# VS Code [Extensions] (Ctrl+Shift+X)์—์„œ ๊ฒ€์ƒ‰ ๋ฐ ์„ค์น˜:
#  - 'Flutter' (Dart ํ™•์žฅ์ด ์ž๋™์œผ๋กœ ํ•จ๊ป˜ ์„ค์น˜๋จ)
#  - 'Awesome Flutter Snippets' (๋‹จ์ถ• ํ‚ค์›Œ๋“œ๋กœ ์œ„์ ฏ ํ…œํ”Œ๋ฆฟ ์ƒ์„ฑ)
#  - 'Error Lens' (์ฝ”๋“œ ์—๋Ÿฌ๋ฅผ ์ธ๋ผ์ธ์œผ๋กœ ์ฆ‰์‹œ ์‹œ๊ฐํ™”)

3. [Step 3] ํ™˜๊ฒฝ ์ง„๋‹จ (flutter doctor) & ์ฒซ ํ”„๋กœ์ ํŠธ ์‹คํ–‰

# 1. ์ „์ฒด ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์ข…ํ•ฉ ์ง„๋‹จ
flutter doctor -v

# ๐ŸŽฏ ๋ชจ๋“  ํ•ญ๋ชฉ์ด ์•„๋ž˜์ฒ˜๋Ÿผ [โœ“] ๋…น์ƒ‰ ์ฒดํฌ๊ฐ€ ๋‚˜์˜ค๋ฉด ์™„๋ฒฝํ•œ ์ค€๋น„ ์™„๋ฃŒ!
# [โœ“] Flutter (Channel stable, 3.x.x, on Microsoft Windows ...)
# [โœ“] Windows Version (Installed version of Windows is version 10 or higher)
# [โœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
# [โœ“] Chrome - develop for the web
# [โœ“] Android Studio (version 2024.x)
# [โœ“] VS Code (version 1.9x)
# [โœ“] Connected device (2 available)

# -------------------------------------------------------------
# ๐Ÿš€ 2. ์ฒซ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ & ์—๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ
# -------------------------------------------------------------
# ์ƒˆ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ (my_first_app)
flutter create my_first_app
cd my_first_app

# ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ๋””๋ฐ”์ด์Šค ํ™•์ธ (Chrome, ์—ฐ๊ฒฐ๋œ ํฐ, ์—๋ฎฌ๋ ˆ์ดํ„ฐ)
flutter devices

# A. ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ์ดˆ๊ณ ์† 1์ดˆ ๋งŒ์— ์‹คํ–‰ํ•ด๋ณด๊ธฐ:
flutter run -d chrome

# B. Android ์—๋ฎฌ๋ ˆ์ดํ„ฐ ์‹คํ–‰ํ•˜๊ธฐ:
# Android Studio -> [Device Manager] -> [Create Device] (Pixel 8 ์„ ํƒ)
# -> ์‹œ์Šคํ…œ ์ด๋ฏธ์ง€(API 34/35) ๋‹ค์šด๋กœ๋“œ ํ›„ ์ƒ์„ฑ -> ์žฌ์ƒ(โ–ถ) ๋ฒ„ํŠผ ํด๋ฆญ
# ์—๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ์ผœ์ง„ ์ƒํƒœ์—์„œ:
flutter run

# C. iOS ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ ์‹คํ–‰ํ•˜๊ธฐ (macOS):
open -a Simulator
flutter run

4. [Step 4] ํ•ซ ๋ฆฌ๋กœ๋“œ ์ฒดํ—˜ & Flutter CLI ํ•„์ˆ˜ ๋ช…๋ น์–ด

# =============================================================
# โšก ํ•ซ ๋ฆฌ๋กœ๋“œ(Hot Reload) ์‹ค์ „ ๊ฐœ๋ฐœ ๋ฃจํ‹ด
# =============================================================
# ์•ฑ์ด ์‹คํ–‰ ์ค‘์ธ ์ƒํƒœ์˜ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹จ์ถ•ํ‚ค:
# [r] : ํ•ซ ๋ฆฌ๋กœ๋“œ (Hot Reload) - ์•ฑ ์ƒํƒœ(์ž…๋ ฅ๊ฐ’, ํ™”๋ฉด ์Šคํƒ)๋ฅผ ๋ณด์กดํ•˜๋ฉด์„œ UI ๋ณ€๊ฒฝ์  0.5์ดˆ ์ฆ‰๊ฐ ๋ฐ˜์˜
# [R] : ํ•ซ ๋ฆฌ์Šคํƒ€ํŠธ (Hot Restart) - ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์•ฑ์„ ์ฒ˜์Œ๋ถ€ํ„ฐ ์žฌ์‹œ์ž‘
# [v] : ๋ธŒ๋ผ์šฐ์ €๋กœ Flutter DevTools ์‹คํ–‰ (์œ„์ ฏ ํŠธ๋ฆฌ ๊ฒ€์‚ฌ, ๋ฉ”๋ชจ๋ฆฌ/CPU ํ”„๋กœํŒŒ์ผ๋Ÿฌ, ๋„คํŠธ์›Œํฌ ๋ชจ๋‹ˆํ„ฐ)
# [h] : ๋‹จ์ถ•ํ‚ค ๋„์›€๋ง ๋ณด๊ธฐ
# [q] : ์•ฑ ์‹คํ–‰ ์ •์ƒ ์ข…๋ฃŒ

# =============================================================
# ๐Ÿ› ๏ธ ํ”„๋กœ์ ํŠธ ์œ ์ง€๋ณด์ˆ˜ & ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ CLI
# =============================================================
# ์˜์กด์„ฑ ํŒจํ‚ค์ง€ ๋‹ค์šด๋กœ๋“œ (pubspec.yaml ๊ธฐ์ค€)
flutter pub get

# ์ƒˆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€ (pubspec.yaml ์ž๋™ ์ˆ˜์ •๋จ)
flutter pub add dio provider flutter_riverpod go_router

# ๊ฐœ๋ฐœ ์ „์šฉ ๋„๊ตฌ ์ถ”๊ฐ€ (์ฝ”๋“œ ์ƒ์„ฑ๊ธฐ ๋“ฑ)
flutter pub add dev:build_runner dev:freezed

# ํŒจํ‚ค์ง€ ์ตœ์‹  ๋ฒ„์ „ ๋ถ„์„ ๋ฐ ์—…๊ทธ๋ ˆ์ด๋“œ
flutter pub outdated
flutter pub upgrade

# ์ฝ”๋“œ ์ •์  ๋ถ„์„ ๋ฐ ํฌ๋งคํŒ…
flutter analyze                     # ๋ฌธ๋ฒ• ์˜ค๋ฅ˜, ๊ฒฝ๊ณ , ๋ฏธ์‚ฌ์šฉ ๋ณ€์ˆ˜ ๊ฒ€์‚ฌ
dart format lib/                    # ๊ณต์‹ ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์— ๋งž์ถฐ ์ž๋™ ์ •๋ ฌ (๋“ค์—ฌ์“ฐ๊ธฐ 2์นธ)

# ๐Ÿ’ก ๋นŒ๋“œ๊ฐ€ ๊ผฌ์ด๊ฑฐ๋‚˜ ์บ์‹œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•  ๋•Œ ๋งŒ๋ณ‘ํ†ต์น˜์•ฝ:
flutter clean                       # build/ ๋ฐ .dart_tool/ ์บ์‹œ ์™„์ „ ์‚ญ์ œ
flutter pub get                     # ํŒจํ‚ค์ง€ ๋‹ค์‹œ ๋ฐ›๊ธฐ

5. ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ & pubspec.yaml ์™„๋ฒฝ ๊ฐ€์ด๋“œ

my_flutter_app/
โ”œโ”€โ”€ android/             โ†’ ์•ˆ๋“œ๋กœ์ด๋“œ ๋„ค์ดํ‹ฐ๋ธŒ ์„ค์ • (Gradle, AndroidManifest.xml)
โ”œโ”€โ”€ ios/                 โ†’ iOS ๋„ค์ดํ‹ฐ๋ธŒ ์„ค์ • (Podfile, Info.plist, Xcode ํ”„๋กœ์ ํŠธ)
โ”œโ”€โ”€ web/                 โ†’ ์›น ๋นŒ๋“œ์šฉ ์—”ํŠธ๋ฆฌ (index.html, manifest.json)
โ”œโ”€โ”€ assets/              โ†’ ์ด๋ฏธ์ง€, ํฐํŠธ, ๋กœ์ปฌ JSON ๋“ฑ ์ •์  ๋ฆฌ์†Œ์Šค (์ƒ์„ฑ ํ•„์š”)
โ”œโ”€โ”€ lib/                 โ†’ ๐Ÿ’ก Dart/Flutter ๋ฉ”์ธ ์†Œ์Šค ์ฝ”๋“œ ๋””๋ ‰ํ† ๋ฆฌ
โ”‚   โ”œโ”€โ”€ main.dart        โ†’ ์•ฑ ์ง„์ž…์  ์—”ํŠธ๋ฆฌํฌ์ธํŠธ (runApp)
โ”‚   โ”œโ”€โ”€ models/          โ†’ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ (DTO, Entity)
โ”‚   โ”œโ”€โ”€ services/        โ†’ API ํ†ต์‹  ๋ฐ ์™ธ๋ถ€ ์„œ๋น„์Šค ๊ณ„์ธต
โ”‚   โ”œโ”€โ”€ providers/       โ†’ ์ƒํƒœ ๊ด€๋ฆฌ ๋กœ์ง
โ”‚   โ”œโ”€โ”€ screens/         โ†’ ๊ฐœ๋ณ„ ํŽ˜์ด์ง€ (Page / Screen)
โ”‚   โ””โ”€โ”€ widgets/         โ†’ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ปค์Šคํ…€ ์œ„์ ฏ
โ”œโ”€โ”€ test/                โ†’ ๋‹จ์œ„ ๋ฐ ์œ„์ ฏ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ
โ””โ”€โ”€ pubspec.yaml         โ†’ ํ”„๋กœ์ ํŠธ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ, ์˜์กด์„ฑ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์—์…‹ ์ •์˜ ํŒŒ์ผ
# pubspec.yaml ํ•ต์‹ฌ ์„ค์ • ์˜ˆ์‹œ
name: my_flutter_app
description: "A modern Flutter mobile application."
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: '>=3.0.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.8
  dio: ^5.7.0                    # ๊ฐ•๋ ฅํ•œ HTTP ๋„คํŠธ์›Œํ‚น ํด๋ผ์ด์–ธํŠธ
  flutter_riverpod: ^2.6.1       # ๋ชจ๋˜ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ƒํƒœ ๊ด€๋ฆฌ
  go_router: ^14.6.0             # ์„ ์–ธํ˜• URL ๋ผ์šฐํŒ…

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^5.0.0

flutter:
  uses-material-design: true
  assets:
    - assets/images/             # ํด๋” ๋‚ด ๋ชจ๋“  ์ด๋ฏธ์ง€ ์—์…‹ ์ž๋™ ๋“ฑ๋ก
    - assets/config.json

6. Dart 3 ํ•ต์‹ฌ ๋ฌธ๋ฒ• ๊ฐ€์ด๋“œ (Dart 3 for Flutter)

// [1] Null Safety (์™„๋ฒฝํ•œ ๋„ ์•ˆ์ „์„ฑ)
String name = "Flutter";         // ๋„ ๋ถˆ๊ฐ€
String? nickname = null;         // ๋„ ๊ฐ€๋Šฅ (?)
int len = nickname?.length ?? 0; // ์•ˆ์ „ ํ˜ธ์ถœ(?.) & ๋„ ๋ณ‘ํ•ฉ ์—ฐ์‚ฐ์ž(??)
nickname ??= "Guest";            // ๋„์ผ ๋•Œ๋งŒ ๊ฐ’ ํ• ๋‹น(??=)

// [2] Dart 3 Records (๋‹ค์ค‘ ๋ฐ˜ํ™˜ ๋ ˆ์ฝ”๋“œ) & Patterns ๊ตฌ์กฐ ๋ถ„ํ•ด
(String, int) getUserInfo() => ("Lucky", 29);
final (userName, userAge) = getUserInfo(); // ํŠœํ”Œ ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น

// ๋ช…๋ช…๋œ ํ•„๋“œ๋ฅผ ๊ฐ€์ง„ ๋ ˆ์ฝ”๋“œ
({String name, int score}) getResult() => (name: "Dart", score: 100);
final result = getResult();
print("${result.name}: ${result.score}");

// [3] Dart 3 Switch ํ‘œํ˜„์‹ (Pattern Matching)
String getRoleBadge(String role) => switch (role) {
  'ADMIN' => '๐Ÿ‘‘ ๊ด€๋ฆฌ์ž',
  'MANAGER' || 'LEAD' => 'โญ ๋งค๋‹ˆ์ €',
  'USER' => '๐Ÿ‘ค ์ผ๋ฐ˜ ํšŒ์›',
  _ => 'โ“ ๋ฏธ์ง€์ •' // default
};

// [4] Cascade ์—ฐ์‚ฐ์ž (..) ๋ฐ ์ปฌ๋ ‰์…˜ if/for
final numbers = [
  1, 2, 3,
  if (true) 4,                    // ์กฐ๊ฑด๋ถ€ ์›์†Œ ์ถ”๊ฐ€
  for (var i = 5; i <= 6; i++) i, // ๋ฐ˜๋ณต๋ฌธ ์›์†Œ ์ถ”๊ฐ€
];

// [5] ์ต์Šคํ…์…˜ (Extension Methods)
extension StringExt on String {
  bool get isValidEmail => contains('@') && contains('.');
}
// bool valid = "test@example.com".isValidEmail;

7. ์œ„์ ฏ ๊ธฐ์ดˆ & ์ƒ๋ช…์ฃผ๊ธฐ (Widget & Lifecycle)

import 'package:flutter/material.dart';

// [1] ์•ฑ ์ง„์ž…์ 
void main() => runApp(const MyApp());

// [2] StatelessWidget: ์ƒํƒœ๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š๋Š” ์ •์  UI ์ปดํฌ๋„ŒํŠธ
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        useMaterial3: true,
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal),
      ),
      home: const CounterScreen(),
    );
  }
}

// [3] StatefulWidget: ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ์œผ๋กœ ํ™”๋ฉด์ด ๊ฐฑ์‹ ๋˜๋Š” ๋™์  ์ปดํฌ๋„ŒํŠธ
class CounterScreen extends StatefulWidget {
  const CounterScreen({super.key});

  @override
  State<CounterScreen> createState() => _CounterScreenState();
}

class _CounterScreenState extends State<CounterScreen> {
  int _counter = 0;

  // 1. ์œ„์ ฏ์ด ํŠธ๋ฆฌ ์ƒ์„ฑ ์‹œ ๋‹จ 1ํšŒ ํ˜ธ์ถœ (์ดˆ๊ธฐํ™”, ๋ฆฌ์Šค๋„ˆ ๋“ฑ๋ก)
  @override
  void initState() {
    super.initState();
    print("initState: ๋ฆฌ์†Œ์Šค ์ดˆ๊ธฐํ™”");
  }

  // 2. ๋ถ€๋ชจ ์œ„์ ฏ์˜ InheritedWidget/Theme์ด ๋ณ€๊ฒฝ๋  ๋•Œ ํ˜ธ์ถœ
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }

  // 3. UI ๋ Œ๋”๋ง (setState ํ˜ธ์ถœ ์‹œ๋งˆ๋‹ค ๋‹ค์‹œ ์‹คํ–‰)
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('์นด์šดํ„ฐ ์˜ˆ์ œ')),
      body: Center(
        child: Text(
          'ํด๋ฆญ ํšŸ์ˆ˜: $_counter',
          style: Theme.of(context).textTheme.headlineMedium,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _counter++; // ์ƒํƒœ ๋ณ€๊ฒฝ ํ›„ UI ์žฌ๋ Œ๋”๋ง ํŠธ๋ฆฌ๊ฑฐ
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }

  // 4. ์œ„์ ฏ์ด ํŠธ๋ฆฌ์—์„œ ์˜๊ตฌ ์ œ๊ฑฐ๋  ๋•Œ ํ˜ธ์ถœ (์ปจํŠธ๋กค๋Ÿฌ, ํƒ€์ด๋จธ ํ•ด์ œ)
  @override
  void dispose() {
    print("dispose: ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฐฉ์ง€ ๋ฆฌ์†Œ์Šค ํ•ด์ œ");
    super.dispose();
  }
}

8. ํ•ต์‹ฌ ๋ ˆ์ด์•„์›ƒ & ์ •๋ ฌ ์œ„์ ฏ (Layout & Sizing)

// [1] Container & SizedBox: ํฌ๊ธฐ, ๋งˆ์ง„, ํŒจ๋”ฉ, ํ…Œ๋‘๋ฆฌ, ๋ฐฐ๊ฒฝ ์ง€์ •
Container(
  width: 200,
  height: 100,
  margin: const EdgeInsets.all(16),
  padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.circular(12),
    boxShadow: [
      BoxShadow(
        color: Colors.black.withOpacity(0.08),
        blurRadius: 10,
        offset: const Offset(0, 4),
      ),
    ],
  ),
  child: const Center(child: Text("์Šคํƒ€์ผ๋“œ ์ปจํ…Œ์ด๋„ˆ")),
);

// ๋‹จ์ˆœ ์—ฌ๋ฐฑ/๊ณต๋ฐฑ ์ค„ ๋•Œ๋Š” ๊ฐ€๋ฒผ์šด SizedBox ๊ถŒ์žฅ
const SizedBox(height: 24); // ์„ธ๋กœ ๊ณต๋ฐฑ

// [2] Column & Row: ์ˆ˜์ง/์ˆ˜ํ‰ ๋ฐฐ์น˜
Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween, // ์ฃผ์ถ•(๊ฐ€๋กœ) ์ •๋ ฌ
  crossAxisAlignment: CrossAxisAlignment.center,     // ๊ต์ฐจ์ถ•(์„ธ๋กœ) ์ •๋ ฌ
  children: [
    const Icon(Icons.star, color: Colors.amber),
    // ๋‚จ์€ ๊ณต๊ฐ„์„ ๋น„์œจ๋Œ€๋กœ ์ฑ„์šฐ๊ธฐ
    Expanded(
      child: Text("๊ธธ์ด๊ฐ€ ๊ธธ์–ด์ ธ๋„ ํ…์ŠคํŠธ๊ฐ€ ์ค„๋ฐ”๊ฟˆ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค."),
    ),
    const Text("์šฐ์ธก ๋"),
  ],
);

// [3] Stack & Positioned: Z-Index ๊ฒน์นจ ๋ ˆ์ด์•„์›ƒ
Stack(
  children: [
    Image.asset('assets/images/bg.jpg', fit: BoxFit.cover),
    Positioned(
      top: 16,
      right: 16,
      child: Badge(label: const Text('NEW'), child: const Icon(Icons.notifications)),
    ),
  ],
);

// [4] Wrap: ์ค„๋ฐ”๊ฟˆ์ด ์ผ์–ด๋‚˜๋Š” ํƒœ๊ทธ/์นฉ ๋ชฉ๋ก
Wrap(
  spacing: 8.0, // ๊ฐ€๋กœ ๊ฐ„๊ฒฉ
  runSpacing: 4.0, // ์„ธ๋กœ(์ค„๋ฐ”๊ฟˆ) ๊ฐ„๊ฒฉ
  children: [
    Chip(label: Text('Flutter')),
    Chip(label: Text('Dart')),
    Chip(label: Text('CrossPlatform')),
  ],
);

9. ๊ณ ์„ฑ๋Šฅ ์Šคํฌ๋กค & ๋ฆฌ์ŠคํŠธ (Scrolling & Slivers)

// [1] ListView.builder: ํ™”๋ฉด์— ๋ณด์ด๋Š” ์•„์ดํ…œ๋งŒ ๊ฐ€์ƒํ™”(Virtualization) ๋ Œ๋”๋ง
ListView.builder(
  itemCount: items.length,
  itemBuilder: (context, index) {
    final item = items[index];
    return ListTile(
      leading: CircleAvatar(child: Text('${index + 1}')),
      title: Text(item.title),
      subtitle: Text(item.desc),
      trailing: const Icon(Icons.arrow_forward_ios, size: 16),
      onTap: () => print('ํด๋ฆญ: ${item.id}'),
    );
  },
);

// [2] ListView.separated: ์•„์ดํ…œ ์‚ฌ์ด์— ๊ตฌ๋ถ„์„ (Divider) ์ž๋™ ์‚ฝ์ž…
ListView.separated(
  itemCount: 20,
  separatorBuilder: (context, index) => const Divider(height: 1),
  itemBuilder: (context, index) => ListTile(title: Text("ํ•ญ๋ชฉ $index")),
);

// [3] GridView.builder: ๋ฐ˜์‘ํ˜• ๊ฒฉ์ž ๋ ˆ์ด์•„์›ƒ
GridView.builder(
  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
    crossAxisCount: 2,        // ํ•œ ์ค„์— 2์—ด
    crossAxisSpacing: 12,     // ๊ฐ€๋กœ ๊ฐ„๊ฒฉ
    mainAxisSpacing: 12,      // ์„ธ๋กœ ๊ฐ„๊ฒฉ
    childAspectRatio: 0.85,   // ๊ฐ€๋กœ/์„ธ๋กœ ๋น„์œจ
  ),
  itemCount: 10,
  itemBuilder: (context, index) => Card(child: Center(child: Text("์นด๋“œ $index"))),
);

// [4] Pull-to-Refresh (๋‹น๊ฒจ์„œ ์ƒˆ๋กœ๊ณ ์นจ)
RefreshIndicator(
  onRefresh: () async {
    await Future.delayed(const Duration(seconds: 1)); // API ์žฌ์กฐํšŒ
  },
  child: ListView(children: [...]),
);

// [5] CustomScrollView & Sliver: ์ ‘ํžˆ๋Š” ํ—ค๋”(Collapsible Appbar)
CustomScrollView(
  slivers: [
    SliverAppBar(
      expandedHeight: 180.0,
      floating: false,
      pinned: true, // ์ƒ๋‹จ ๊ณ ์ •
      flexibleSpace: FlexibleSpaceBar(
        title: const Text('ํ”„๋กœํ•„ ์ƒ์„ธ'),
        background: Image.asset('assets/images/banner.jpg', fit: BoxFit.cover),
      ),
    ),
    SliverList(
      delegate: SliverChildBuilderDelegate(
        (context, index) => ListTile(title: Text("ํ”ผ๋“œ ์•„์ดํ…œ $index")),
        childCount: 30,
      ),
    ),
  ],
);

10. Material 3 UI ์ปดํฌ๋„ŒํŠธ & ์ž…๋ ฅ ํผ (UI & Forms)

// [1] ๋ฒ„ํŠผ ์ข…๋ฅ˜ ๋ชจ์Œ
FilledButton(onPressed: () {}, child: const Text("์ฃผ์š” ์ž‘์—…"));
ElevatedButton(onPressed: () {}, child: const Text("๊ธฐ๋ณธ ๋ฒ„ํŠผ"));
OutlinedButton(onPressed: () {}, child: const Text("์™ธ๊ณฝ์„  ๋ฒ„ํŠผ"));
TextButton(onPressed: () {}, child: const Text("ํ…์ŠคํŠธ ๋งํฌ"));
IconButton(icon: const Icon(Icons.favorite), onPressed: () {});

// [2] ๋ชจ๋‹ฌ & ๋ฐ”ํ…€์‹œํŠธ ํ˜ธ์ถœ
// SnackBar ํ‘œ์‹œ
ScaffoldMessenger.of(context).showSnackBar(
  SnackBar(
    content: const Text('์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'),
    action: SnackBarAction(label: '์‹คํ–‰์ทจ์†Œ', onPressed: () {}),
  ),
);

// Alert Dialog ๋‹ค์ด์–ผ๋กœ๊ทธ
showDialog(
  context: context,
  builder: (context) => AlertDialog(
    title: const Text('์‚ญ์ œ ํ™•์ธ'),
    content: const Text('์ •๋ง๋กœ ์ด ํ•ญ๋ชฉ์„ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?'),
    actions: [
      TextButton(onPressed: () => Navigator.pop(context), child: const Text('์ทจ์†Œ')),
      FilledButton(onPressed: () => Navigator.pop(context), child: const Text('์‚ญ์ œ')),
    ],
  ),
);

// Modal Bottom Sheet ๋ฐ”ํ…€์‹œํŠธ
showModalBottomSheet(
  context: context,
  shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
  builder: (context) => Container(
    padding: const EdgeInsets.all(20),
    child: const Text('ํ•˜๋‹จ ์‹œํŠธ ์ฝ˜ํ…์ธ '),
  ),
);

// [3] ์œ ํšจ์„ฑ ๊ฒ€์ฆ(Validation) ํผ ์˜ˆ์ œ
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();

Form(
  key: _formKey,
  child: Column(
    children: [
      TextFormField(
        controller: _emailController,
        keyboardType: TextInputType.emailAddress,
        decoration: const InputDecoration(
          labelText: '์ด๋ฉ”์ผ ์ฃผ์†Œ',
          prefixIcon: Icon(Icons.email),
          border: OutlineInputBorder(),
        ),
        validator: (value) {
          if (value == null || value.isEmpty) return '์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
          if (!value.contains('@')) return '์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.';
          return null; // ํ†ต๊ณผ
        },
      ),
      const SizedBox(height: 16),
      FilledButton(
        onPressed: () {
          if (_formKey.currentState!.validate()) {
            print("ํผ ๊ฒ€์ฆ ์„ฑ๊ณต: ${_emailController.text}");
          }
        },
        child: const Text('์ œ์ถœํ•˜๊ธฐ'),
      ),
    ],
  ),
);

11. ๋‚ด๋น„๊ฒŒ์ด์…˜ & GoRouter ๋ผ์šฐํŒ… (Navigation)

// ๐Ÿ’ก [1] ์ „ํ†ต์ ์ธ Navigator 1.0 (๊ฐ„๋‹จํ•œ ํ™”๋ฉด ์ด๋™)
// ํŽ˜์ด์ง€ ์ด๋™
Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => const DetailScreen(id: 42)),
);

// ์ด์ „ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„๊ฐ€๊ธฐ & ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
Navigator.pop(context, "๊ฒฐ๊ณผ ๋ฐ์ดํ„ฐ");

// ๋’ค๋กœ๊ฐ€๊ธฐ ๋ถˆ๊ฐ€๋Šฅํ•œ ๋Œ€์ฒด ์ด๋™ (๋กœ๊ทธ์ธ โž” ํ™ˆ ์ด๋™ ์‹œ ํ•„์ˆ˜)
Navigator.pushReplacement(
  context,
  MaterialPageRoute(builder: (context) => const HomeScreen()),
);

// -------------------------------------------------------------
// ๐Ÿš€ [2] ํ˜„๋Œ€์ ์ธ ์„ ์–ธํ˜• ๋ผ์šฐํŒ…: GoRouter (๊ณต์‹ ๊ถŒ์žฅ, ๋”ฅ๋งํฌ ์™„๋ฒฝ ์ง€์›)
// -------------------------------------------------------------
import 'package:go_router/go_router.dart';

final goRouter = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const HomeScreen(),
      routes: [
        // ์ค‘์ฒฉ ๋ผ์šฐํŠธ: /product/:id
        GoRoute(
          path: 'product/:id',
          builder: (context, state) {
            final id = state.pathParameters['id']!;
            final query = state.uri.queryParameters['ref'] ?? '';
            return ProductDetailScreen(productId: id);
          },
        ),
      ],
    ),
    GoRoute(
      path: '/login',
      builder: (context, state) => const LoginScreen(),
    ),
  ],
  // ์ธ์ฆ ๊ฐ€๋“œ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
  redirect: (context, state) {
    final bool isLoggedIn = AuthService.isLoggedIn;
    final bool isLoggingIn = state.matchedLocation == '/login';
    if (!isLoggedIn && !isLoggingIn) return '/login';
    if (isLoggedIn && isLoggingIn) return '/';
    return null;
  },
);

// MaterialApp์— ์—ฐ๊ฒฐ:
// MaterialApp.router(routerConfig: goRouter);

// ์ฝ”๋“œ์—์„œ ๋ผ์šฐํŠธ ์ด๋™:
// context.go('/product/100');         // ์Šคํƒ ๊ต์ฒด
// context.push('/product/100');       // ์œ„์— ์Šคํƒ ์Œ“๊ธฐ
// context.pop();                      // ๋’ค๋กœ ๊ฐ€๊ธฐ

12. ์ƒํƒœ ๊ด€๋ฆฌ ํ•ต์‹ฌ ํŒจํ„ด (Riverpod & Provider)

// =============================================================
// [1] Flutter Riverpod (์ตœ์‹  ์‹ค๋ฌด ๋Œ€์„ธ & ํƒ€์ž… ์•ˆ์ „์„ฑ)
// =============================================================
import 'package:flutter_riverpod/flutter_riverpod.dart';

// 1. ๋‹จ์ˆœ ์ƒํƒœ ํ”„๋กœ๋ฐ”์ด๋” ์ •์˜
final counterProvider = StateProvider<int>((ref) => 0);

// 2. ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ฐ€์ง„ Notifier ์ •์˜
class TodoNotifier extends StateNotifier<List<String>> {
  TodoNotifier() : super([]);

  void add(String text) => state = [...state, text];
  void remove(int index) => state = state.whereIndexed((i, _) => i != index).toList();
}

final todoProvider = StateNotifierProvider<TodoNotifier, List<String>>(
  (ref) => TodoNotifier(),
);

// 3. UI์—์„œ ๊ตฌ๋… (ConsumerWidget ์‚ฌ์šฉ)
class RiverpodCounterView extends ConsumerWidget {
  const RiverpodCounterView({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // ref.watch: ์ƒํƒœ ๋ณ€๊ฒฝ ์‹œ ์ž๋™ ์œ„์ ฏ ๋ฆฌ๋นŒ๋“œ
    final count = ref.watch(counterProvider);

    return Scaffold(
      body: Center(child: Text("Riverpod Count: $count")),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // ref.read: ์ด๋ฒคํŠธ ์ฝœ๋ฐฑ์—์„œ ์ƒํƒœ ๊ฐฑ์‹ 
          ref.read(counterProvider.notifier).state++;
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}

// =============================================================
// [2] Provider (์ „ํ†ต์  ํŒจํ„ด)
// =============================================================
class UserProvider extends ChangeNotifier {
  String _name = 'Guest';
  String get name => _name;

  void updateName(String newName) {
    _name = newName;
    notifyListeners(); // ๊ตฌ๋… ์ค‘์ธ UI์— ๊ฐฑ์‹  ์•Œ๋ฆผ
  }
}

// UI์—์„œ:
// context.watch<UserProvider>().name;               // ๊ฐ’ ๋ณ€๊ฒฝ ์‹œ ๋ฆฌ๋นŒ๋“œ
// context.read<UserProvider>().updateName('Lucky'); // ์ฝœ๋ฐฑ์—์„œ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ

13. ๋น„๋™๊ธฐ ํ†ต์‹  & API ๋„คํŠธ์›Œํ‚น (Async & Dio)

import 'dart:convert';
import 'package:dio/dio.dart';

// [1] ๋ชจ๋ธ ์ •์˜ (fromJson / toJson)
class Post {
  final int id;
  final String title;

  Post({required this.id, required this.title});

  factory Post.fromJson(Map<String, dynamic> json) {
    return Post(
      id: json['id'] as int,
      title: json['title'] as String,
    );
  }
}

// [2] Dio๋ฅผ ์‚ฌ์šฉํ•œ REST API ํ˜ธ์ถœ ์„œ๋น„์Šค
class ApiService {
  final Dio _dio = Dio(
    BaseOptions(
      baseUrl: 'https://jsonplaceholder.typicode.com',
      connectTimeout: const Duration(seconds: 5),
      receiveTimeout: const Duration(seconds: 3),
      headers: {'Content-Type': 'application/json'},
    ),
  );

  Future<List<Post>> getPosts() async {
    try {
      final res = await _dio.get('/posts');
      final list = res.data as List;
      return list.map((json) => Post.fromJson(json)).toList();
    } on DioException catch (e) {
      throw Exception('API ์—๋Ÿฌ: ${e.response?.statusCode} - ${e.message}');
    }
  }
}

// [3] FutureBuilder๋ฅผ ์ด์šฉํ•œ ๋กœ๋”ฉ/์—๋Ÿฌ/์„ฑ๊ณต ์ƒํƒœ ์ž๋™ UI ๋ Œ๋”๋ง
class PostListScreen extends StatelessWidget {
  final ApiService api = ApiService();
  PostListScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก')),
      body: FutureBuilder<List<Post>>(
        future: api.getPosts(),
        builder: (context, snapshot) {
          // 1. ๋กœ๋”ฉ ์ƒํƒœ
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          }
          // 2. ์—๋Ÿฌ ์ƒํƒœ
          if (snapshot.hasError) {
            return Center(child: Text('์˜ค๋ฅ˜ ๋ฐœ์ƒ: ${snapshot.error}'));
          }
          // 3. ์„ฑ๊ณต ์ƒํƒœ
          final posts = snapshot.data ?? [];
          return ListView.builder(
            itemCount: posts.length,
            itemBuilder: (context, i) => ListTile(
              title: Text(posts[i].title),
            ),
          );
        },
      ),
    );
  }
}

14. ์ œ์Šค์ฒ˜, ์• ๋‹ˆ๋ฉ”์ด์…˜ & ํ…Œ๋งˆ (Animations & Theme)

// [1] ํ„ฐ์น˜ ๊ฐ์ง€: GestureDetector vs InkWell
InkWell(
  onTap: () => print("๋ฌผ๊ฒฐ ๋ฆฌํ”Œ ํšจ๊ณผ ํ„ฐ์น˜"),
  borderRadius: BorderRadius.circular(8),
  child: const Padding(padding: EdgeInsets.all(12), child: Text("ํด๋ฆญ ๊ฐ€๋Šฅ ์˜์—ญ")),
);

// [2] ์•”์‹œ์  ์• ๋‹ˆ๋ฉ”์ด์…˜ (Implicit Animations - ๊ฐ„ํŽธํ•˜๊ณ  ๋ถ€๋“œ๋Ÿฌ์šด ์ „ํ™˜)
AnimatedContainer(
  duration: const Duration(milliseconds: 300),
  curve: Curves.easeInOut,
  width: isExpanded ? 200 : 100,
  height: isExpanded ? 200 : 100,
  decoration: BoxDecoration(
    color: isExpanded ? Colors.teal : Colors.blueGrey,
    borderRadius: BorderRadius.circular(isExpanded ? 30 : 8),
  ),
);

AnimatedOpacity(
  opacity: isVisible ? 1.0 : 0.0,
  duration: const Duration(milliseconds: 250),
  child: const Text("ํŽ˜์ด๋“œ ์ธ/์•„์›ƒ ํ…์ŠคํŠธ"),
);

// [3] Hero ์• ๋‹ˆ๋ฉ”์ด์…˜ (ํ™”๋ฉด ๊ฐ„ ์ด๋ฏธ์ง€ ์ „ํ™˜ ๋งˆ๋ฒ•)
// ํ™”๋ฉด 1:
Hero(
  tag: 'product-image-42',
  child: Image.asset('assets/images/item.png'),
);
// ํ™”๋ฉด 2์—์„œ๋„ ๋™์ผ tag ๋ถ€์—ฌ ์‹œ ํ™”๋ฉด ์ „ํ™˜ ๊ฐ„ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ํฌ๊ธฐ/์œ„์น˜ ์ด๋™ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ฐœ์ƒ!

// [4] ๋‹คํฌ ๋ชจ๋“œ & ํ…Œ๋งˆ ์„ค์ •
MaterialApp(
  themeMode: ThemeMode.system, // ์‹œ์Šคํ…œ ์„ค์ •(๋ผ์ดํŠธ/๋‹คํฌ) ์ž๋™ ์ถ”์ข…
  theme: ThemeData(
    useMaterial3: true,
    brightness: Brightness.light,
    colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo, brightness: Brightness.light),
  ),
  darkTheme: ThemeData(
    useMaterial3: true,
    brightness: Brightness.dark,
    colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo, brightness: Brightness.dark),
  ),
);

15. ๋นŒ๋“œ, ํ…Œ์ŠคํŠธ & ๋ฐฐํฌ ๋ช…๋ น์–ด (Build & Deployment)

# [1] ์ฝ”๋“œ ๋ถ„์„ ๋ฐ ์ •์  ๊ฒ€์‚ฌ
flutter analyze                      # Dart ๋ฆฐํŠธ ๋ฐ ๊ฒฝ๊ณ  ๊ฒ€์‚ฌ
dart format lib/                     # ์ฝ”๋“œ ์Šคํƒ€์ผ ์ž๋™ ํฌ๋งคํŒ… (2์นธ ๋“ค์—ฌ์“ฐ๊ธฐ)

# [2] ํ…Œ์ŠคํŠธ ์‹คํ–‰
flutter test                         # ์ „์ฒด ๋‹จ์œ„/์œ„์ ฏ ํ…Œ์ŠคํŠธ ์‹คํ–‰
flutter test test/widget_test.dart   # ํŠน์ • ํ…Œ์ŠคํŠธ ํŒŒ์ผ ์‹คํ–‰

# [3] Android ๋ฆด๋ฆฌ์Šค ๋นŒ๋“œ
flutter build apk --release          # ๋‹จ์ผ ํ†ตํ•ฉ APK ์ƒ์„ฑ (build/app/outputs/flutter-apk/)
flutter build apk --split-per-abi    # CPU ์•„ํ‚คํ…์ฒ˜๋ณ„ ๊ฒฝ๋Ÿ‰ํ™” APK(v7a, v8a, x86_64) ๋ถ„ํ•  ๋นŒ๋“œ (์šฉ๋Ÿ‰ ์ตœ์ ํ™”!)
flutter build appbundle --release    # ๊ตฌ๊ธ€ ํ”Œ๋ ˆ์ด์Šคํ† ์–ด ๋ฐฐํฌ์šฉ AAB ํŒŒ์ผ ์ƒ์„ฑ (๊ถŒ์žฅ)

# [4] iOS ๋ฆด๋ฆฌ์Šค ๋นŒ๋“œ (macOS & Xcode ํ•„์ˆ˜)
flutter build ipa --release          # App Store ๋ฐฐํฌ์šฉ ์•„์นด์ด๋ธŒ ์ƒ์„ฑ
# ์ƒ์„ฑ๋œ .ipa ํŒŒ์ผ์„ Transporter ์•ฑ ๋˜๋Š” Xcode Organizer๋ฅผ ํ†ตํ•ด App Store Connect ์—…๋กœ๋“œ

# [5] Web ๋ฆด๋ฆฌ์Šค ๋นŒ๋“œ
flutter build web --release          # ์›น ํ˜ธ์ŠคํŒ…์šฉ ๋นŒ๋“œ (build/web/ ํด๋” ์ƒ์„ฑ)
flutter build web --wasm             # WebAssembly ์ตœ์‹  ๊ฐ€์† ๋นŒ๋“œ (์‹คํ—˜์  ๊ณ ์„ฑ๋Šฅ)

# [6] ๋นŒ๋“œ ์‹œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ „๋‹ฌ (--dart-define)
flutter run --dart-define=API_URL=https://api.mycompany.com --dart-define=ENV=dev
flutter build apk --release --dart-define=API_URL=https://prod.mycompany.com
# Dart ์ฝ”๋“œ์—์„œ ์ฐธ์กฐ:
# const apiUrl = String.fromEnvironment('API_URL', defaultValue: 'https://dev.api.com');
๐Ÿ’ฌ

์˜๊ฒฌ ๋ฐ ์งˆ๋ฌธ

0
0 / 1500