Button
Flutter์์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฒํผ ์์ ฏ์ ์ ๋ฆฌํด๋ดค์ด์! 
โข
โข
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โฆ
โข
Flutter ๋ฒํผ ์์ ฏ ์ข
๋ฅ
๋ฒํผ ์์ ฏ | ์ค๋ช
|
ElevatedButton | ์
์ฒด๊ฐ ์๋ ๋ฒํผ (๊ธฐ๋ณธ ๋ฒํผ) |
TextButton | ๋ฐฐ๊ฒฝ ์์ด ํ
์คํธ๋ง ์๋ ๋ฒํผ |
OutlinedButton | ์ธ๊ณฝ์ ์ด ์๋ ๋ฒํผ |
IconButton | ์์ด์ฝ๋ง ์๋ ๋ฒํผ |
FloatingActionButton (FAB) | ๋ฅ๊ทผ ์ํ ๋ฒํผ (์ฃผ๋ก ์ก์
๋ฒํผ์ผ๋ก ์ฌ์ฉ) |
PopupMenuButton | ํ์
๋ฉ๋ด๋ฅผ ์ ๊ณตํ๋ ๋ฒํผ |
DropdownButton | ๋๋กญ๋ค์ด ํํ์ ๋ฒํผ |
InkWell | ํฐ์น ํจ๊ณผ๊ฐ ์๋ ์ปค์คํ
๋ฒํผ |
GestureDetector | ๋ชจ๋ ํฐ์น ์ด๋ฒคํธ๋ฅผ ๊ฐ์งํ ์ ์๋ ๋ฒํผ ๋์ฒด ์์ ฏ |
๊ฐ ๋ฒํผ๋ณ ์ฝ๋ ์์
1. ElevatedButton (์
์ฒด ๋ฒํผ)
ElevatedButton(
onPressed: () {
print("ElevatedButton ํด๋ฆญ!");
},
child: Text("ElevatedButton"),
),
Dart
๋ณต์ฌ
2. TextButton (ํ
์คํธ ๋ฒํผ)
TextButton(
onPressed: () {
print("TextButton ํด๋ฆญ!");
},
child: Text("TextButton"),
),
Dart
๋ณต์ฌ
3. OutlinedButton (์ธ๊ณฝ์ ๋ฒํผ)
OutlinedButton(
onPressed: () {
print("OutlinedButton ํด๋ฆญ!");
},
child: Text("OutlinedButton"),
),
Dart
๋ณต์ฌ
4. IconButton (์์ด์ฝ ๋ฒํผ)
IconButton(
icon: Icon(Icons.thumb_up),
onPressed: () {
print("IconButton ํด๋ฆญ!");
},
),
Dart
๋ณต์ฌ
5. FloatingActionButton (FAB)
FloatingActionButton(
onPressed: () {
print("FloatingActionButton ํด๋ฆญ!");
},
child: Icon(Icons.add),
),
Dart
๋ณต์ฌ
6. PopupMenuButton (ํ์
๋ฉ๋ด ๋ฒํผ)
PopupMenuButton<String>(
onSelected: (value) {
print("์ ํํ ๊ฐ: $value");
},
itemBuilder: (context) => [
PopupMenuItem(value: "์ต์
1", child: Text("์ต์
1")),
PopupMenuItem(value: "์ต์
2", child: Text("์ต์
2")),
],
),
Dart
๋ณต์ฌ
7. DropdownButton (๋๋กญ๋ค์ด ๋ฒํผ)
DropdownButton<String>(
value: "์ต์
1",
onChanged: (newValue) {
print("์ ํํ ๊ฐ: $newValue");
},
items: [
DropdownMenuItem(value: "์ต์
1", child: Text("์ต์
1")),
DropdownMenuItem(value: "์ต์
2", child: Text("์ต์
2")),
],
),
Dart
๋ณต์ฌ
8. InkWell (์ปค์คํ
ํฐ์น ๋ฒํผ)
InkWell(
onTap: () {
print("InkWell ํด๋ฆญ!");
},
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
),
child: Text("InkWell ๋ฒํผ", style: TextStyle(color: Colors.white)),
),
),
Dart
๋ณต์ฌ
9. GestureDetector (๋ชจ๋ ํฐ์น ์ด๋ฒคํธ ๊ฐ์ง)
GestureDetector(
onTap: () {
print("GestureDetector ํด๋ฆญ!");
},
child: Container(
padding: EdgeInsets.all(16),
color: Colors.green,
child: Text("GestureDetector ๋ฒํผ", style: TextStyle(color: Colors.white)),
),
),
Dart
๋ณต์ฌ
๊ณตํต ์์ ฏ์ผ๋ก ์ ์ํ๊ธฐ
์ปค์คํ
๋ฒํผ์ ์์ ฏ์ผ๋ก ์ ์ํ๊ณ , ํ๋ก์ ํธ์ ๊ณตํต ์์ ฏ์ผ๋ก ์ฌ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ด
๋๋ค.
์ปค์คํ
๋ฒํผ์ ๋ง๋ค๊ธฐ ์ํด์๋ StatelessWidget์ ์์๋ฐ์ ์๋ก์ด ์์ ฏ ํด๋์ค๋ฅผ ์ ์ํฉ๋๋ค. ์ด๋ ๊ฒ ๋ง๋ ์ปค์คํ
๋ฒํผ์ ํ๋ก์ ํธ ์ ์ฒด์์ ์ฌ์ฌ์ฉํ ์ ์์ต๋๋ค.
CustomButton
class CustomButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final Color color;
const CustomButton({
Key? key,
required this.text,
required this.onPressed,
this.color = Colors.blue,
}) : super(key: key);
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
primary: color,
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
text,
style: TextStyle(fontSize: 16),
),
);
}
}
Dart
๋ณต์ฌ
์ฌ์ฉ ์์
CustomButton(
text: "์ปค์คํ
๋ฒํผ",
onPressed: () {
print("์ปค์คํ
๋ฒํผ ํด๋ฆญ!");
},
color: Colors.green,
)
Dart
๋ณต์ฌ
์ด๋ ๊ฒ ์ ์ํ ์ปค์คํ
๋ฒํผ์ ๋ค์๊ณผ ๊ฐ์ ์ฅ์ ์ด ์์ต๋๋ค.
โข
โข
โข
โข