์ ๋ ฅ ์์ ฏ
โข
TextField
โข
Checbox
โข
Radio
โข
Switch
โข
Button
โฆ
TextButton
โฆ
ElevatedButton
โฆ
OutlineButton
TextField
์ฌ์ฉ์๋ก๋ถํฐ ํ
์คํธ๋ฅผ ์
๋ ฅ๋ฐ์ ์ ์๋ ์์ ฏ
๋ฌธ๋ฒ
TextField(
controller: TextEditingController(), // ํ
์คํธ ํ๋์ ๊ฐ๊ณผ ์ํธ ์์ฉํ๊ธฐ ์ํ ์ปจํธ๋กค๋ฌ (์ต์
)
decoration: InputDecoration(
labelText: 'Enter your text', // ํ
์คํธ ํ๋์ ๋ผ๋ฒจ (์ต์
)
hintText: 'Type something...', // ํ
์คํธ ํ๋ ๋ด์ ํํธ๋ฅผ ์ ๊ณต (์ต์
)
),
onChanged: (value) {
// ํ
์คํธ๊ฐ ๋ณ๊ฒฝ๋ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('TextField Example'),
),
body: Center(
child: TextField(
controller: TextEditingController(),
decoration: InputDecoration(
labelText: 'Enter your text',
hintText: 'Type something...',
),
onChanged: (value) {
print('Text value changed: $value');
},
),
),
),
);
}
}
Dart
๋ณต์ฌ
Checbox
์ฌ์ฉ์๊ฐ ์ ํ ์ฌ๋ถ๋ฅผ ๋ํ๋ผ ์ ์๋ ์์ ฏ
๋ฌธ๋ฒ
Checkbox(
value: true, // ์ฒดํฌ๋ฐ์ค์ ์ด๊ธฐ๊ฐ (true ๋๋ false)
onChanged: (value) {
// ์ฒดํฌ๋ฐ์ค์ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Checkbox Example'),
),
body: Center(
child: Checkbox(
value: true,
onChanged: (value) {
print('Checkbox value changed: $value');
},
),
),
),
);
}
}
Dart
๋ณต์ฌ
Radio
์ฌ๋ฌ ์ต์
์ค ํ๋๋ฅผ ์ ํํ ์ ์๋ ๋ผ๋์ค ๋ฒํผ ์์ ฏ
๋ฌธ๋ฒ
Radio(
value: 1, // ๋ผ๋์ค ๋ฒํผ์ ๊ฐ
groupValue: selectedValue, // ๊ทธ๋ฃน ๋ด์์ ํ์ฌ ์ ํ๋ ๊ฐ
onChanged: (value) {
// ๋ผ๋์ค ๋ฒํผ์ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
int selectedValue = 1;
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Radio Example'),
),
body: Center(
child: Radio(
value: 1,
groupValue: selectedValue,
onChanged: (value) {
print('Radio value changed: $value');
},
),
),
),
);
}
}
Dart
๋ณต์ฌ
Switch
์ฌ์ฉ์๊ฐ ํน์ ์ต์
์ ์ํ๋ฅผ ํ ๊ธํ ์ ์๋ ์ค์์น ์์ ฏ
๋ฌธ๋ฒ
Switch(
value: true, // ์ค์์น์ ์ด๊ธฐ๊ฐ (true ๋๋ false)
onChanged: (value) {
// ์ค์์น์ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Switch Example'),
),
body: Center(
child: Switch(
value: true,
onChanged: (value) {
print('Switch value changed: $value');
},
),
),
),
);
}
}
Dart
๋ณต์ฌ
Button
โข
TextButton
โข
ElevatedButton
โข
OutlineButton
TextButton
๊ฐ๋จํ ํ
์คํธ ๋ฒํผ
๋ฌธ๋ฒ
TextButton(
onPressed: () {
// ๋ฒํผ์ด ๋๋ ธ์ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
child: Text('Press me'), // ๋ฒํผ์ ํ์๋ ํ
์คํธ
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('TextButton Example'),
),
body: Center(
child: TextButton(
onPressed: () {
print('TextButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
๋ณต์ฌ
ElevatedButton
๋์ ํ๋ฉด์์ ๋ ์ค๋ฅด๋ ํจ๊ณผ๋ฅผ ๊ฐ์ง ๋ฒํผ
๋ฌธ๋ฒ
ElevatedButton(
onPressed: () {
// ๋ฒํผ์ด ๋๋ ธ์ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
child: Text('Press me'), // ๋ฒํผ์ ํ์๋ ํ
์คํธ
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('ElevatedButton Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
print('ElevatedButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
๋ณต์ฌ
OutlineButton
์ธ๊ณฝ์ ์ด ์๋ ๋ฒํผ
๋ฌธ๋ฒ
OutlinedButton(
onPressed: () {
// ๋ฒํผ์ด ๋๋ ธ์ ๋ ์คํ๋๋ ์ฝ๋ฐฑ ํจ์
},
child: Text('Press me'), // ๋ฒํผ์ ํ์๋ ํ
์คํธ
)
Dart
๋ณต์ฌ
์์
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('OutlinedButton Example'),
),
body: Center(
child: OutlinedButton(
onPressed: () {
print('OutlinedButton pressed');
},
child: Text('Press me'),
),
),
),
);
}
}
Dart
๋ณต์ฌ
Flutter ์ ๋ ฅ ์์ ฏ ๋ถ๋ฅ
1. ์ผ๋ฐ ์ ๋ ฅ ์์ ฏ (Form๊ณผ ๊ด๊ณ ์์)
Form์ validate(), save()์ ์ฐ๊ฒฐ๋์ง ์๋ ์์ ฏ
์์ ฏ | ์ค๋ช
|
TextField | ํ
์คํธ ์
๋ ฅ |
Checkbox | ์ฒดํฌ๋ฐ์ค |
Radio | ๋ผ๋์ค ๋ฒํผ |
Switch | ์ค์์น |
Slider | ์ฌ๋ผ์ด๋ |
DropdownButton | ๋๋กญ๋ค์ด |
Button | ์ผ๋ฐ ๋ฒํผ |
TextButton | ํ
์คํธ ๋ฒํผ |
ElevatedButton | ๊ฐ์กฐ ๋ฒํผ |
OutlinedButton | ํ
๋๋ฆฌ ๋ฒํผ |
ํน์ง
โข
Form ์์ด ์ฌ์ฉ
โข
validator ์์
โข
onSaved ์์
โข
onChanged๋ก ๊ฐ ์ฒ๋ฆฌ
โข
Controller๋ก ๊ฐ ๊ด๋ฆฌ
์์
TextField(
onChanged: (value) {
print(value);
},
)
Checkbox(
value: isChecked,
onChanged: (value) {
setState(() {
isChecked = value!;
});
},
)
Dart
๋ณต์ฌ
2. Form์ฉ ์ ๋ ฅ ์์ ฏ (FormField ๊ณ์ด)
Form ์์์ ์ฌ์ฉํ๋ฉฐ, validate(), save() ์ฌ์ฉ ๊ฐ๋ฅ
Form ์์ ฏ | ์ค๋ช
|
TextFormField | ํ
์คํธ ์
๋ ฅ |
DropdownButtonFormField | ๋๋กญ๋ค์ด |
FormField | ์ปค์คํ
ํผ ์์ ฏ |
Checkbox โ FormField๋ก ๊ฐ์ธ์ ์ฌ์ฉ | |
Radio โ FormField๋ก ๊ฐ์ธ์ ์ฌ์ฉ | |
Switch โ FormField๋ก ๊ฐ์ธ์ ์ฌ์ฉ |
ํน์ง
โข
Form ์์์ ์ฌ์ฉ
โข
validator ์ฌ์ฉ ๊ฐ๋ฅ
โข
onSaved ์ฌ์ฉ ๊ฐ๋ฅ
โข
FormState.validate()
โข
FormState.save()
์์
TextFormField(
validator: (value) {
if (value!.isEmpty) return "๊ฐ ์
๋ ฅ";
return null;
},
onSaved: (value) {
print(value);
},
)
Dart
๋ณต์ฌ
3. Checkbox / Radio / Switch ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
checkbox, radio, switch ์ด ์์ ฏ๋ค์ Form ์ ์ฉ ์์ ฏ์ด ์์ด์, FormField๋ก ๊ฐ์ธ์ ์ฌ์ฉ
FormField<bool>(
initialValue: false,
onSaved: (value) {
print(value);
},
builder: (state) {
return CheckboxListTile(
value: state.value,
onChanged: (value) {
state.didChange(value);
},
title: Text("์ฝ๊ด ๋์"),
);
},
)
Dart
๋ณต์ฌ
ํต์ฌ ์ฝ๋
state.didChange(value);
Dart
๋ณต์ฌ
โ Form์ ๊ฐ ์ ๋ฌ
4. ์ ์ฒด ์์ ฏ ๋ถ๋ฅ ์ ๋ฆฌ (๋งค์ฐ ์ค์)
์ผ๋ฐ ์ ๋ ฅ ์์ ฏ
TextField
Checkbox
Radio
Switch
Slider
DropdownButton
Plain Text
๋ณต์ฌ
Form ์ ๋ ฅ ์์ ฏ
TextFormField
DropdownButtonFormField
FormField (Checkbox, Radio, Switch ์ปค์คํ
)
Plain Text
๋ณต์ฌ
๋ฒํผ
TextButton
ElevatedButton
OutlinedButton
Plain Text
๋ณต์ฌ
๋ฒํผ์ Form ์์ ฏ์ด ์๋๋ผ
Form ์คํ ํธ๋ฆฌ๊ฑฐ ์ญํ
5. Flutter Form ๊ตฌ์กฐ (์ค์)
Form
โโ TextFormField
โโ DropdownButtonFormField
โโ FormField (Checkbox)
โโ FormField (Radio)
โโ ElevatedButton (Submit)
Plain Text
๋ณต์ฌ
6. ์ค๋ฌด ๊ธฐ์ค ์ฌ์ฉ ๊ตฌ๋ถ
ํ๋ฉด | ์์ ฏ |
๋ก๊ทธ์ธ | TextFormField |
ํ์๊ฐ์
| TextFormField + Form |
๊ฒ์์ฐฝ | TextField |
์ค์ ํ๋ฉด | Switch |
์ค๋ฌธ์กฐ์ฌ | FormField |
๊ฒ์๊ธ ์์ฑ | TextFormField |
ํํฐ | DropdownButton |
์ ๋ฆฌ
โข
์ผ๋ฐ ์
๋ ฅ ์์ ฏ: TextField, Checkbox, Radio, Switch (Form ์์ด ์ฌ์ฉ)
โข
Form ์
๋ ฅ ์์ ฏ: TextFormField, DropdownButtonFormField, FormField (validate/save ๊ฐ๋ฅ)
โข
Button: TextButton, ElevatedButton, OutlinedButton (Form ์คํ ํธ๋ฆฌ๊ฑฐ)
graph TD
A["์
๋ ฅ ์์ ฏ"] --> B{"Form ์ฌ์ฉ?"}
B -->|"No"| C["์ผ๋ฐ ์
๋ ฅ ์์ ฏ"]
B -->|"Yes"| D["Form ์
๋ ฅ ์์ ฏ"]
C --> C1["TextField"]
C --> C2["Checkbox"]
C --> C3["Radio"]
C --> C4["Switch"]
D --> D1["TextFormField"]
D --> D2["DropdownButtonFormField"]
D --> D3["FormField"]
D1 --> E["Form"]
D2 --> E
D3 --> E
E --> F["FormState"]
F --> F1["validate()"]
F --> F2["save()"]
F --> F3["reset()"]
G["Button"] --> H["Form ์คํ"]
H --> F1Mermaid
๋ณต์ฌ

Flutter ์
๋ ฅ ์์ ฏ ๊ตฌ์กฐ ํต์ฌ ๊ฐ๋
Flutter ์
๋ ฅ ์์คํ
๊ตฌ์กฐ๋ฅผ ์ดํดํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
graph TD
A["Input Widget"] --> B["FormField"]
B --> C["Form"]
C --> D["FormState"]
D --> E["validate()"]
D --> F["save()"]
D --> G["reset()"]Mermaid
๋ณต์ฌ
์ด ๊ตฌ์กฐ ์ดํดํ๋ฉด Flutter Form ๊ฑฐ์ ์์ ํ ์ดํดํ ๊ฒ์
๋๋ค.
๊ฐ์๋
ธํธ์ฉ์ผ๋ก Flutter ์
๋ ฅ ์์ ฏ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ 3๊ฐ์ง ์ ๋ฆฌํด๋๋ฆฌ๊ฒ ์ต๋๋ค.
์ด๊ฑฐ ์ค๋ฌด์์ ๋งค์ฐ ์ค์ํ ๊ฐ๋
์
๋๋ค.
Flutter ์ ๋ ฅ ์์ ฏ ๊ฐ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ 3๊ฐ์ง
1. Controller ๋ฐฉ์
2. Form ๋ฐฉ์
3. Map ๋ฐฉ์ (Form + onSaved)
1. Controller ๋ฐฉ์
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ
๊ฐ TextField / TextFormField๋ง๋ค Controller๋ฅผ ์ฐ๊ฒฐํ๊ณ
controller.text ๋ก ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
๊ตฌ์กฐ
TextEditingController controller = TextEditingController();
Dart
๋ณต์ฌ
TextField(
controller: controller,
)
Dart
๋ณต์ฌ
print(controller.text);
Dart
๋ณต์ฌ
์์
final emailController = TextEditingController();
final passwordController = TextEditingController();
ElevatedButton(
onPressed: () {
print(emailController.text);
print(passwordController.text);
},
child: Text("๋ก๊ทธ์ธ"),
)
Dart
๋ณต์ฌ
ํน์ง
ํญ๋ชฉ | ์ค๋ช
|
๊ฐ ๊ฐ์ ธ์ค๊ธฐ | controller.text |
์ค์๊ฐ ๋ณ๊ฒฝ | ๊ฐ๋ฅ |
์ด๊ธฐ๊ฐ ์ค์ | controller.text = |
์
๋ ฅ๊ฐ ์ ์ด | ๊ฐ๋ฅ |
๋จ์ | ํ๋ ๋ง์ผ๋ฉด controller ๋ง์์ง |
์ธ์ ์ฌ์ฉ?
๋ก๊ทธ์ธ
๊ฒ์์ฐฝ
์ฑํ
์
๋ ฅ
ํ๋กํ ์์
ํ
์คํธ ์ ์ด ํ์ํ ๋
Plain Text
๋ณต์ฌ
2. Form ๋ฐฉ์ (onSaved)
Form + TextFormField + onSaved ์ฌ์ฉ
Form์ save()๊ฐ ํธ์ถ๋ ๋
๊ฐ TextFormField์ onSaved ์คํ๋จ
๊ตฌ์กฐ
Form
TextFormField
onSaved
formKey.currentState!.save()
Dart
๋ณต์ฌ
์์
final _formKey = GlobalKey<FormState>();
String email = '';
String password = '';
Form(
key: _formKey,
child: Column(
children: [
TextFormField(
onSaved: (value) {
email = value!;
},
),
TextFormField(
onSaved: (value) {
password = value!;
},
),
ElevatedButton(
onPressed: () {
_formKey.currentState!.save();
print(email);
print(password);
},
child: Text("์ ์ฅ"),
)
],
),
)
Dart
๋ณต์ฌ
ํน์ง
ํญ๋ชฉ | ์ค๋ช
|
๊ฐ ์ ์ฅ ์์ | save() ํธ์ถ |
validator | ์ฌ์ฉ ๊ฐ๋ฅ |
controller ํ์ | ์์ |
์
๋ ฅ ๋ง์ ๋ | ์ข์ |
์ธ์ ์ฌ์ฉ?
ํ์๊ฐ์
์ค๋ฌธ์กฐ์ฌ
๊ฒ์๊ธ ์์ฑ
๊ด๋ฆฌ์ ์
๋ ฅํผ
์
๋ ฅ ํ๋ ๋ง์ ํ๋ฉด
Plain Text
๋ณต์ฌ
3. Map ๋ฐฉ์ (์ค๋ฌด์์ ๋ง์ด ์ฌ์ฉ)
Form + onSaved + Map ์ ์ฅ ๋ฐฉ์
API ์ ์กํ ๋ ๊ฐ์ฅ ํธํจ
๊ตฌ์กฐ
Map<String, String> formData = {};
Dart
๋ณต์ฌ
TextFormField(
onSaved: (value) => formData['email'] = value!,
)
Dart
๋ณต์ฌ
_formKey.currentState!.save();
print(formData);
Dart
๋ณต์ฌ
์์
final _formKey = GlobalKey<FormState>();
Map<String, String> formData = {};
Form(
key: _formKey,
child: Column(
children: [
TextFormField(
decoration: InputDecoration(labelText: "Email"),
onSaved: (value) => formData['email'] = value!,
),
TextFormField(
decoration: InputDecoration(labelText: "Password"),
onSaved: (value) => formData['password'] = value!,
),
ElevatedButton(
onPressed: () {
_formKey.currentState!.save();
print(formData);
},
child: Text("์ ์ก"),
)
],
),
)
Dart
๋ณต์ฌ
๊ฒฐ๊ณผ
{
email: test.com,
password: 1234
}
Dart
๋ณต์ฌ
4. ์ธ ๊ฐ์ง ๋ฐฉ๋ฒ ๋น๊ต (์ค์)
๋ฐฉ์ | ํน์ง | ์ฌ์ฉ |
Controller | ์ง์ ์ ์ด | ๋ก๊ทธ์ธ, ๊ฒ์ |
Form | save ์ ์ ์ฅ | ์
๋ ฅํผ |
Map | API ์ ์ก | ํ์๊ฐ์
|
onChanged | ์ค์๊ฐ | ๊ฒ์ |
5. ์ค๋ฌด ๊ธฐ์ค ์ ํ ๋ฐฉ๋ฒ (์ค์)
์
๋ ฅ ํ๋ ์ ๋ค โ Controller
์
๋ ฅ ํ๋ ๋ง๋ค โ Form
์๋ฒ ์ ์ก โ Map
์ค์๊ฐ ๊ฒ์ โ onChanged
Plain Text
๋ณต์ฌ
Flutter ์
๋ ฅ ์ฒ๋ฆฌ ์ ์ฒด ๊ตฌ์กฐ ์ ๋ฆฌ
์
๋ ฅ ์์ ฏ ๊ฐ ๊ฐ์ ธ์ค๊ธฐ ๋ฐฉ๋ฒ
1. Controller ๋ฐฉ์
controller.text
2. Form ๋ฐฉ์
onSaved โ save()
3. Map ๋ฐฉ์
onSaved โ Map ์ ์ฅ โ API ์ ์ก
Plain Text
๋ณต์ฌ

์ค๋ฌด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๋ ํจํด
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
api.send(formData);
}
Dart
๋ณต์ฌ
์ด ๊ตฌ์กฐ๋
Flutter ๋ก๊ทธ์ธ / ํ์๊ฐ์
/ ๊ฒ์ํ / ์ผํ๋ชฐ / ๊ด๋ฆฌ์ ํ์ด์ง ์ ๋ถ ๋์ผํ ํจํด์
๋๋ค.





