์ถ์ฒ
https://docs.flutter.dev/get-started/codelab
Write your first Flutter app, part 1
How to write a web-based app in Flutter.
docs.flutter.dev

- ์คํํธ์ ํ์ฌ์ ์ ์๋ ์ด๋ฆ์ ์์ฑํ๋ ๊ฐ๋จํ ์ฑ ๊ตฌํ
- ์ฌ์ฉ์๋ ์ด๋ฆ ์ ํ, ์ทจ์, ๊ฐ์ฅ ์ข์ ์ด๋ฆ ์ ์ฅ ๊ฐ๋ฅ
- ์ฝ๋๋ ํ ๋ฒ์ 10๊ฐ์ ์ด๋ฆ์ ๋๋ฆฌ๊ฒ ์์ฑํจ
- ์ฌ์ฉ์๊ฐ ์คํฌ๋กค ํ๋ฉด ๋ ๋ง์ ์ด๋ฆ์ด ์์ฑ๋จ
- ์คํฌ๋กค ์ ํ ์์
Part 1 ์์ ๋ฐฐ์ธ ๋ด์ฉ
- iOS, Android, ๋ฐ์คํฌํฑ(์: Windows) ๋ฐ ์น์์ ์์ฐ์ค๋ฝ๊ฒ ๋ณด์ด๋ Flutter ์ฑ์ ์์ฑํ๋ ๋ฐฉ๋ฒ
- Flutter ์ฑ์ ๊ธฐ๋ณธ ๊ตฌ์กฐ
- ๊ธฐ๋ฅ ํ์ฅ์ ์ํ ํจํค์ง ์ฐพ๊ธฐ ๋ฐ ์ฌ์ฉ
- ๋ ๋น ๋ฅธ ๊ฐ๋ฐ ์ฃผ๊ธฐ๋ฅผ ์ํด ํซ ๋ฆฌ๋ก๋ ์ฌ์ฉ
- stateful widget ๊ตฌํํ๋ ๋ฐฉ๋ฒ
- ๋ฌดํํ ๋๋ฆฌ๊ฒ ๋ก๋๋ ๋ชฉ๋ก์ ๋ง๋๋ ๋ฐฉ๋ฒ
์ด ์ฝ๋๋ฉ์ 2๋ถ์์๋ ๋ํํ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ณ ์ฑ์ ํ ๋ง๋ฅผ ์์ ํ๋ฉฐ ์ ํ๋ฉด(Flutter์์๋ a route ๋ผ๊ณ ํจ)์ผ๋ก ์ด๋ํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํฉ๋๋ค.
์ฌ์ฉํ ํญ๋ชฉ
์ด ์ค์ต์ ์๋ฃํ๋ ค๋ฉด Flutter SDK์ ํธ์ง๊ธฐ๋ผ๋ ๋ ๊ฐ์ง ์ํํธ์จ์ด๊ฐ ํ์ํฉ๋๋ค. ์ด Codelab์ Android Studio๋ฅผ ๊ฐ์ ํ์ง๋ง ์ ํธํ๋ ํธ์ง๊ธฐ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๋ค์ ๊ธฐ๊ธฐ ์ค ํ๋๋ฅผ ์ฌ์ฉํ์ฌ ์ด ์ฝ๋๋ฉ์ ์คํํ ์ ์์ต๋๋ค.
- ์ปดํจํฐ์ ์ฐ๊ฒฐ๋๊ณ ๊ฐ๋ฐ์ ๋ชจ๋๋ก ์ค์ ๋ ๋ฌผ๋ฆฌ์ ์ฅ์น(Android ๋๋ iOS)
- iOS ์๋ฎฌ๋ ์ดํฐ(Xcode ๋๊ตฌ ์ค์น ํ์)
- Android ์๋ฎฌ๋ ์ดํฐ(Android Studio์์ ์ค์ ํ์)
- ๋ธ๋ผ์ฐ์ (๋๋ฒ๊น ์ ์ํด์๋ Chrome์ด ํ์ํฉ๋๋ค)
- Windows, Linux ๋๋ macOS ๋ฐ์คํฌํ ์ ํ๋ฆฌ์ผ์ด์
์ฌ๋ฌ๋ถ์ด ๋ง๋๋ ๋ชจ๋ Flutter ์ฑ์ ์น์ฉ์ผ๋ก๋ ์ปดํ์ผ๋ฉ๋๋ค. ์ฅ์น ํ๋ค์ด ์๋์ IDE ๋๋ flutter ์ฅ์น๋ฅผ ์ฌ์ฉํ๋ command line์์ ์ด์ Chrome ๋ฐ ์น ์๋ฒ๊ฐ ๋์ด๋์ด ์์ด์ผ ํฉ๋๋ค. Chrome ๊ธฐ๊ธฐ๋ ์๋์ผ๋ก Chrome์ ์์ํฉ๋๋ค. ์น ์๋ฒ๋ ๋ชจ๋ ๋ธ๋ผ์ฐ์ ์์ ์ฑ์ ๋ก๋ํ ์ ์๋๋ก ์ฑ์ ํธ์คํ
ํ๋ ์๋ฒ๋ฅผ ์์ํฉ๋๋ค. DevTools๋ฅผ ์ฌ์ฉํ ์ ์๋๋ก ๊ฐ๋ฐ ์ค์๋ Chrome ๊ธฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๊ณ , ๋ค๋ฅธ ๋ธ๋ผ์ฐ์ ์์ ํ
์คํธํ ๋๋ ์น ์๋ฒ๋ฅผ ์ฌ์ฉํ์ธ์. ์์ธํ ๋ด์ฉ์ Flutter๋ก ์น ์ ํ๋ฆฌ์ผ์ด์
๋น๋ ๋ฐ ์น์์ ์ฒซ Flutter ์ฑ ์์ฑ์ ์ฐธ์กฐํ์ธ์.
๋ํ Flutter ์ฑ์ ๋ฐ์คํฌํฑ์ฉ์ผ๋ก ์ปดํ์ผํ ์ ์์ต๋๋ค. Windows(๋ฐ์คํฌํฑ) ๋๋ flutter ์ฅ์น๋ฅผ ์ฌ์ฉํ๋ command line๊ณผ ๊ฐ์ ์ฅ์น ์๋์ IDE์ ๋์ด๋ ์ด์ ์ฒด์ ๋ฅผ ํ์ธํด์ผ ํฉ๋๋ค. ๋ฐ์คํฌํฑ์ฉ ์ฑ ๋น๋์ ๋ํ ์์ธํ ๋ด์ฉ์ Flutter ๋ฐ์คํฌํฑ ์ ํ๋ฆฌ์ผ์ด์
์์ฑ์ ์ฐธ์กฐํ์ธ์.
Step 1: Create the starter Flutter app
Dart ์ฝ๋๊ฐ ์๋ lib/main.dart๋ฅผ ์ฃผ๋ก ํธ์งํ ๊ฒ์ด๋ค.
ํ๋ฉด ์ค์์ "Hello World"๊ฐ ํ์๋๋ ์ฝ๋์ด๋ค.
Tip: When pasting code into your app, indentation can become skewed. You can fix this with the following Flutter tools:
- Android Studio and IntelliJ IDEA: Right-click the code and select Reformat Code with dartfmt.
- VS Code: Right-click and select Format Document.
- Terminal: Run flutter format <filename>.

Observations
- ์ด ์์ ์์๋ Material ์ฑ์ ๋ง๋ญ๋๋ค. ๋จธํฐ๋ฆฌ์ผ์ ๋ชจ๋ฐ์ผ๊ณผ ์น์์ ํ์ค์ด ๋๋ ์๊ฐ ๋์์ธ ์ธ์ด์ ๋๋ค. Flutter๋ ํ๋ถํ Material ์์ ฏ ์ธํธ๋ฅผ ์ ๊ณตํฉ๋๋ค. pubspec.yaml ํ์ผ์ flutter ์น์ ์ uses-material-design: true ํญ๋ชฉ์ด ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ๋ฏธ๋ฆฌ ์ ์๋ ์์ด์ฝ ์ธํธ์ ๊ฐ์ ๋จธํฐ๋ฆฌ์ผ์ ๋ ๋ง์ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ์ฑ์ ์ฑ ์์ฒด๋ฅผ ์์ ฏ์ผ๋ก ๋ง๋๋ StatelessWidget์ ํ์ฅํฉ๋๋ค. Flutter์์๋ ์ ๋ ฌ, ํจ๋ฉ ๋ฐ ๋ ์ด์์์ ํฌํจํ์ฌ ๊ฑฐ์ ๋ชจ๋ ๊ฒ์ด ์์ ฏ์ ๋๋ค.
- Material ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ Scaffold ์์ ฏ์ ๊ธฐ๋ณธ ์ฑ ๋ฐ์ ํ ํ๋ฉด์ ์์ ฏ ํธ๋ฆฌ๋ฅผ ๋ณด์ ํ๋ ๋ฐ๋ ์์ฑ์ ์ ๊ณตํฉ๋๋ค. ์์ ฏ ํ์ ํธ๋ฆฌ๋ ๋งค์ฐ ๋ณต์กํ ์ ์์ต๋๋ค.
- ์์ ฏ์ ์ฃผ์ ์์ ์ ๋ค๋ฅธ ํ์ ์์ค ์์ ฏ๊ณผ ๊ด๋ จํ์ฌ ์์ ฏ์ ํ์ํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ build() ๋ฉ์๋๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ๋๋ค.
- ์ด ์์ ์ ๋ณธ๋ฌธ์ Text ์์ ์์ ฏ์ ํฌํจํ๋ Center ์์ ฏ์ผ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. Center ์์ ฏ์ ์์ ฏ ํ์ ํธ๋ฆฌ๋ฅผ ํ๋ฉด ์ค์์ ์ ๋ ฌํฉ๋๋ค.
Step 2: Use an external package
์คํ์์ค ํจํค์ง english_words ๋ฅผ ์ฌ์ฉํด๋ณด์!
* ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ์์ฒ ๊ฐ์ ์์ด ๋จ์ด์ ๋ช ๊ฐ์ง ์ ํธ๋ฆฌํฐ ๊ธฐ๋ฅ์ด ํฌํจ๋์ด ์์
pub.dev ์์ english_words ์
๋ค๋ฅธ
๋ค์ํ ์คํ์์ค ํจํค์ง๋ค์ ์ฐพ์ ์ ์๋ค
- english_words ํจํค์ง๋ฅผ ํ๋ก์ ํธ์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํ์.
$ flutter pub add english_words Resolving dependencies... + english_words 4.0.0 path 1.8.0 (1.8.1 available) source_span 1.8.1 (1.8.2 available) test_api 0.4.3 (0.4.9 available) Downloading english_words 4.0.0... Changed 1 dependency!
pubspec.yaml ํ์ผ์ ํ๋ฌํฐ ์ฑ์์ assets๊ณผ dependencies๋ฅผ ๊ด๋ฆฌํ๋ค.
pubspec.yaml ์์ english_words dependency๊ฐ ์ถ๊ฐ ๋ ๊ฒ์ ๋ณด๊ฒ ๋ ๊ฒ์ด๋ค
2. Android Studio์์ pubspec.yaml ํ์ผ์ ๋ณด๋ ๋์ Pub get ์ ํด๋ฆญ ํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ํจํค์ง๋ฅผ ํ๋ก์ ํธ๋ก ๊ฐ์ ธ์ต๋๋ค. ์ฝ์์ ๋ค์์ด ํ์๋์ด์ผ ํฉ๋๋ค.
$ flutter pub get Running "flutter pub get" in startup_namer... Process finished with exit code 0
Pub get ์ ์ํ ํ๋ฉด ํ๋ก์ ํธ์ ๊ฐ์ ธ์จ ๋ชจ๋ ํจํค์ง ๋ชฉ๋ก๊ณผ ํด๋น ๋ฒ์ ๋ฒํธ๊ฐ ํฌํจ๋ pubspec.lock ํ์ผ์ด ์๋ ์์ฑ ๋ฉ๋๋ค.
3. lib/main.dart, import the new package:
import 'package:english_words/english_words.dart';
4. "Hello World" ๋ฌธ์์ด์ ์ฌ์ฉํ๋ ๋์ English words package๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ๋ฅผ ์์ฑํฉ๋๋ค.
// Copyright 2018 The Flutter team. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:english_words/english_words.dart'; import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { final wordPair = WordPair.random(); return MaterialApp( title: 'Welcome to Flutter', home: Scaffold( appBar: AppBar( title: const Text('Welcome to Flutter'), ), body: Center( child: child: Text(wordPair.asPascalCase), ), ), ); } }
์ฐธ๊ณ :
"Pascal case"("upper camel case"๋ผ๊ณ ๋ ํจ)๋ ์ฒซ ๋ฒ์งธ ๋จ์ด๋ฅผ ํฌํจํ์ฌ ๋ฌธ์์ด์ ๊ฐ ๋จ์ด๊ฐ ๋๋ฌธ์๋ก ์์ํจ์ ์๋ฏธํฉ๋๋ค. ๋ฐ๋ผ์ "uppercamelcase"๋ "UpperCamelCase"๊ฐ ๋ฉ๋๋ค.
Pascal case = upper camel case
uppercamelcase -> UpperCamelCase
5. hot reload ํด๋ฆญ or save ํ ๋ ๋ง๋ค ๋ฌด์์๋ก ์ ํ๋ ๋ค๋ฅธ ๋จ์ด ์์ด ํ์๋์ด์ผ ํ๋ค.
๋จ์ด ์์ด build ๋ฉ์๋ (๋ ๋๋ง์ด ํ์ ํ ๋ ์คํ or Flutter Inspector์์ Platform์ ํ ๊ธํ ๋ ์คํ) ๋ด์์ ์์ฑ๋๊ธฐ ๋๋ฌธ์
Step 3: Add a Stateful widget
Stateless ์์ ฏ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ์ฆ, ์์ฑ์ ๋ณ๊ฒฝํ ์ ์์ผ๋ฉฐ ๋ชจ๋ ๊ฐ์ด final
Stateful ์์ ฏ์ ์์ ฏ์ ์๋ช ๋์ ๋ณ๊ฒฝ๋ ์ ์๋ ์ํ๋ฅผ ์ ์งํฉ๋๋ค. Stateful ์์ ฏ์ ๊ตฌํํ๋ ค๋ฉด ์ต์ํ ๋ ๊ฐ์ ํด๋์ค๊ฐ ํ์ํฉ๋๋ค.
1) StatefulWidget class - ์ธ์คํด์ค๋ฅผ ์์ฑ
2) State class. StatefulWidget class๋ ์์ฒด๋ก ๋ถ๋ณ์ด๋ฉฐ ๋ฒ๋ฆฌ๊ณ ๋ค์ ์์ฑํ ์ ์์ง๋ง Stateํด๋์ค๋ ์์ ฏ์ ์๋ช ๋์ ์ง์๋ฉ๋๋ค.
Stateful ์์ ฏ ์ ์ถ๊ฐํ์ : RandomWords / State class : _RandomWordsState
๊ทธ๋ฐ ๋ค์ RandomWords๋ฅผ ๊ธฐ์กด MyApp stateless widget ๋ด์์ ์์์ผ๋ก ์ฌ์ฉํ๋ค.
1. stateful widget ์ ๋ํ boilerplate code ์์ฑ
stful ์ ์น๋ฉด Stateful ์์ ฏ ์ ์์ฑํ ๊ฒ์ธ์ง ๋ฌป์ต๋๋ค. Return ํค ๋ฅผ ๋๋ฌ ์๋ฝํฉ๋๋ค.
๋ ํด๋์ค์ ๋ํ boilerplate code๊ฐ ๋ํ๋๊ณ ์ปค์๋ stateful widget์ ์ด๋ฆ์ ์ ๋ ฅํ ์ ์๋ ์์น์ ์์ต๋๋ค.
2. ์์ ฏ์ด๋ฆ์ผ๋ก RandomWords ์ ๋ ฅ
RandomWords ์์ ฏ ์ State ํด๋์ค๋ฅผ ๋ง๋๋ ๊ฒ ์ธ์ ๋ค๋ฅธ ์์ ์ ๊ฑฐ์ ์ํํ์ง ์์ต๋๋ค.
RandomWords๋ฅผ stateful widget ์ด๋ฆ์ผ๋ก ์ ๋ ฅ ํ๋ฉด IDE์์ ์๋์ผ๋ก State ํด๋์ค๋ฅผ ์ ๋ฐ์ดํธํ์ฌ ์ด๋ฆ์ _RandomWordsState๋ก ์ง์ ํฉ๋๋ค . ๊ธฐ๋ณธ์ ์ผ๋ก State ํด๋์ค ์ด๋ฆ์๋ ์ธ๋๋ฐ๊ฐ ์ ๋์ฌ๋ก ๋ถ์ต๋๋ค. ์๋ณ์ ์ ๋์ฌ์ ๋ฐ์ค ์ ์ถ๊ฐํ๋ฉด Dart ์ธ์ด์์ ๊ฐ์ธ์ ๋ณด ๊ฐ ๋ณดํธ๋๋ฉฐ State ๊ฐ์ฒด ์ ๊ถ์ฅ๋๋ ๋ชจ๋ฒ ์ฌ๋ก์ ๋๋ค .
IDE๋ ๋ํ ์๋์ผ๋ก ์ํ ํด๋์ค๋ฅผ ํ์ฅํ์ฌ ์ ๋ฐ์ดํธํ์ฌ ๋ค์ ๊ณผ ํจ๊ป ์ฌ์ฉํ๋๋ก ํน์ํ ๋ ์ผ๋ฐ ํด๋์ค๋ฅผ ์ฌ์ฉํ๊ณ ์์์ ๋ํ๋ ๋๋ค.
class RandomWords extends StatefulWidget { const RandomWords({ Key? key }) : super(key: key); @override State<RandomWords> createState() => _RandomWordsState(); } class _RandomWordsState extends State<RandomWords> { @override Widget build(BuildContext context) { return Container(); } }
https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2#0
Write Your First Flutter App, part 2 | Google Codelabs
Flutter is Googleโs UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. In this codelab, youโll extend a simple mobile app to add interactivity, navigation, and change its theme color.
codelabs.developers.google.com
- web์์
https://docs.flutter.dev/get-started/codelab-web
Write your first Flutter app on the web
How to create a Flutter web app.
docs.flutter.dev
'Mobile > Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Flutter] Erros.. (0) | 2023.03.08 |
---|---|
[Flutter] (0) | 2022.05.20 |
์ฃผ์ (0) | 2020.05.18 |
Dart cheatsheet codelab (0) | 2020.01.02 |