์žฌ๋ฐŒ๋Š”๊ฑฐ๐ŸŒˆ

Flutter_04. Button ๋ณธ๋ฌธ

๊ฐœ๋ฐœํ•˜๊ธฐ/Flutter Start

Flutter_04. Button

uraon 2023. 4. 27. 20:00
728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๋‹ค์–‘ํ•œ ๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ TextButton์„ ์ž…๋ ฅํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅ๋œ๋‹ค. ์‰ฝ๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด, onPressed๋Š” ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ถœ๋ ฅ๋˜๋Š” ์ด๋ฒคํŠธ๊ฐ€ ์ •์˜๋˜๋Š” ๋ถ€๋ถ„์ด๊ณ , child๋Š” ๋ฒ„ํŠผ๋ช…์„ ๋„ฃ๋Š”๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

 

#์Šคํƒ€์ผ : styleFrom()์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ€์ผ ์„ค์ • ๊ฐ€๋Šฅ

style: TextButton.styleFrom()

 

#๋ณ„๋„ Function์„ ๋งŒ๋“ค์–ด์„œ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ๊ตฌํ˜„ ๊ฐ€๋Šฅ

  // -- Function ----
  longClickAction() {
    String action = "long clicked";
    print('text button is $action.');
  }

 

 

 

 

 

 

 

TextButton

TextButton(
       style: TextButton.styleFrom(foregroundColor: const Color.fromARGB(255, 79, 54, 244)),
       onLongPress: () => longClickAction(),
       onPressed: () {
           // --- Button Event ---
           print('text button is clicked.');
       },
       child: const Text(
           'Text Button',
           style: TextStyle(fontSize: 20),
       )
),

 

 

 

๐ŸŒˆ Button์˜ ๊ธฐ๋Šฅ์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด?

Command๋ฅผ ๋ˆ„๋ฅธ ์ƒํƒœ๋กœ ํ•ด๋‹น ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด๋ณด์ž. 

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•ด๋‹น ๋ฒ„ํŠผ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ๋“ค์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

ElevatedButton

ElevatedButton(
       onPressed: (){
           // --- Button Event ---
           print('Elevated button is clicked.');
       },
       style: ElevatedButton.styleFrom(
       backgroundColor: const Color.fromARGB(255, 79, 54, 244),
       shape: RoundedRectangleBorder(
           borderRadius: BorderRadius.circular(10)
           )
       ),
       child: const Text('Elevated button'),
),

 

#style: ElevatedButton.styleFrom()

- ๋ฒ„ํŠผ ์นผ๋ผ backgroundColor: const Color.fromARGB(255, 79, 54, 244),
- ๋ฒ„ํŠผ ๋ชจ์–‘ shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10) )

 

 

 

 

 

OutlinedButton

 

OutlinedButton(
       onPressed: (){
           // --- Button Event ---
           print('Outline Button is clicked.');
       },
       style: OutlinedButton.styleFrom(
           foregroundColor: const Color.fromARGB(255, 79, 54, 244),
           side: const BorderSide(
               color: Colors.black,
               width: 2,
           )
       ),
       child: const Text('Outlined button'),
),

 

#style: OutlinedButton.styleFrom()

- ๋ฒ„ํŠผ ์นผ๋ผ backgroundColor: const Color.fromARGB(255, 79, 54, 244),
- ๋ฒ„ํŠผ ๋ผ์ธ side: const BorderSide( color: Colors.black, width: 2, )

 

 

 

 

 

 

 

TextButton.icon

 

TextButton.icon(
       onPressed: (){
           // --- Button Event ---
           print("TextButton Icon is clicked.");
       },
       icon: const Icon(
           Icons.home,
           size: 30,
           color: Colors.black,
       ),
       label: const Text("Go to home"),
       style: TextButton.styleFrom(
           foregroundColor: const Color.fromARGB(255, 79, 54, 244)
       ),
),

 

#icon: const Icon()

- ์•„์ด์ฝ˜ ์ด๋ฏธ์ง€ Icons.home,
- ์•„์ด์ฝ˜ ์‚ฌ์ด์ฆˆ size: 30,
- ์•„์ด์ฝ˜ ์นผ๋ผ color: Colors.black,

 

#label: const Text()

- ํ…์ŠคํŠธ ๋ฒ„ํŠผ๋ช… label: const Text("Go to home"),

 

#style: TextButton.styleFrom()

- ํ…์ŠคํŠธ ๋ฒ„ํŠผ ์นผ๋ผ style: TextButton.styleFrom( foregroundColor: const Color.fromARGB(255, 79, 54, 244) ),

 

 

 

 

 

 

ElevatedButton.icon

 

ElevatedButton.icon(
       onPressed: (){
           // --- Button Event ---
           print("Elevated Button Icon is clicked.");
       },
       icon: const Icon(
           Icons.home,
           size: 20,
       ),
       label: const Text('Home'),
       style: ElevatedButton.styleFrom(
           backgroundColor: const Color.fromARGB(255, 79, 54, 244),
           minimumSize: const Size(130, 40)
       ),
),

 

#style: ElevatedButton.styleFrom()

- ๋ฒ„ํŠผ ์นผ๋ผ backgroundColor: const Color.fromARGB(255, 79, 54, 244),
- ๋ฒ„ํŠผ ์ตœ์†Œ ์‚ฌ์ด์ฆˆ minimumSize: const Size(130, 40)

 

 

 

 

 

 

OutlinedButton.icon

 

 

OutlinedButton.icon(
       onPressed: (){
           // --- Button Event ---
           print("OutlinedButton Icon is clicked.");
       },
       icon: const Icon(
           Icons.home,
           size: 20
       ),
       label: const Text("Go to Home"),
       style: OutlinedButton.styleFrom(
           foregroundColor: Colors.black,
           side: const BorderSide(
               color: Colors.black,
               width: 2,
           )
       ),
)

 

#style: OutlinedButton.styleFrom()

- ๋ฒ„ํŠผ ํ…์ŠคํŠธ ์นผ๋ผ foregroundColor: Colors.black,
- ๋ณด๋” ์นผ๋ผ์™€ ๋‘๊ป˜ side: const BorderSide( color: Colors.black, width: 2, )

 

 

 

 

 


์œ„์— 6๊ฐ€์ง€ ๋ฒ„ํŠผ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถœ๋ ฅ๋œ๋‹ค.

์ด ๊ธฐ๋ณธ ์ฝ”๋“œ๋“ค์„ ์ž˜ ํ™œ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ๋ฒ„ํŠผ ์Šคํƒ€์ผ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

์‹ค์ œ๋กœ ํด๋ฆญ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•˜์—ฌ print๋ฅผ ๋„ฃ์–ด ํ™•์ธํ•˜์ž. ํ•˜์ง€๋งŒ! ์‹ค์ œ ์•ฑ์„ ์˜ฌ๋ฆด๋•Œ์—๋Š” ๋ฐ˜๋“œ์‹œ ๋ชจ๋“  print๋ฅผ ์ œ๊ฑฐํ•ด์•ผ ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค!

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœํ•˜๊ธฐ > Flutter Start' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Flutter_06. GestureDetector, onTap, AlertDialog  (0) 2023.05.02
Flutter_05. Button, Link, launchUrl, Plugins  (0) 2023.04.29
Flutter_03. CircleAvatar, Divider, Button  (0) 2023.04.24
Flutter_02. Column(Image), ScrollView, Padding, Row  (0) 2023.04.16
Flutter_01. ์‹œ์ž‘  (1) 2023.04.13