์ ๋ ฅ ์์ ฏ
โข
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
๋ณต์ฌ