Search

Button

Button

Flutter์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฒ„ํŠผ ์œ„์ ฏ์„ ์ •๋ฆฌํ•ด๋ดค์–ด์š”!
โ€ข
Flutter ๋ฒ„ํŠผ ์œ„์ ฏ ์ข…๋ฅ˜
โ€ข
๊ฐ ๋ฒ„ํŠผ๋ณ„ ์ฝ”๋“œ ์˜ˆ์ œ
โ—ฆ
1. ElevatedButton (์ž…์ฒด ๋ฒ„ํŠผ)
โ—ฆ
2. TextButton (ํ…์ŠคํŠธ ๋ฒ„ํŠผ)
โ—ฆ
3. OutlinedButton (์™ธ๊ณฝ์„  ๋ฒ„ํŠผ)
โ—ฆ
4. IconButton (์•„์ด์ฝ˜ ๋ฒ„ํŠผ)
โ—ฆ
5. FloatingActionButton (FAB)
โ—ฆ
6. PopupMenuButton (ํŒ์—… ๋ฉ”๋‰ด ๋ฒ„ํŠผ)
โ—ฆ
7. DropdownButton (๋“œ๋กญ๋‹ค์šด ๋ฒ„ํŠผ)
โ—ฆ
8. InkWell (์ปค์Šคํ…€ ํ„ฐ์น˜ ๋ฒ„ํŠผ)
โ—ฆ
9. GestureDetector (๋ชจ๋“  ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๊ฐ์ง€)
โ€ข
์ปค์Šคํ…€ ๋ฒ„ํŠผ ์ •์˜ํ•˜๊ธฐ

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
๋ณต์‚ฌ
์ด๋ ‡๊ฒŒ ์ •์˜ํ•œ ์ปค์Šคํ…€ ๋ฒ„ํŠผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
โ€ข
์ฝ”๋“œ ์žฌ์‚ฌ์šฉ์„ฑ ํ–ฅ์ƒ
โ€ข
์ผ๊ด€๋œ ๋””์ž์ธ ์‹œ์Šคํ…œ ๊ตฌํ˜„
โ€ข
์œ ์ง€๋ณด์ˆ˜ ์šฉ์ด์„ฑ
โ€ข
๋ฒ„ํŠผ ์Šคํƒ€์ผ ์ค‘์•™ ๊ด€๋ฆฌ