์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- stateful
- flutter
- switch
- Webflow
- ElevatedButton
- POP
- button
- textField
- drawer
- sizedbox
- TextEditingController
- Scaffold
- GestureDetector
- vscode
- ontap
- Snackbar
- scaffoldmessenger
- FloatingActionButton
- figma
- image
- dart
- slider
- navigator
- Routing
- list
- PushNamed
- icon
- AppBar
- InputDecoration
- AlertDialog
- Today
- Total
์ฌ๋ฐ๋๊ฑฐ๐
Flutter_13. Stateful, Switch, setState, Button ๋ณธ๋ฌธ
์ค์์น๋ ์ค์์น์ ๊ฐ์ ์๊ณ ์์ ์ ์ญ ๋ณ์๊ฐ ํ์ํ๋ค.
์์ธํ ์๊ฐ๋ ์๋ ๋งํฌ ์ฐธ๊ณ :)
https://api.flutter.dev/flutter/material/Switch-class.html
Switch class - material library - Dart API
A Material Design switch. Used to toggle the on/off state of a single setting. The switch itself does not maintain any state. Instead, when the state of the switch changes, the widget calls the onChanged callback. Most widgets that use a switch will listen
api.flutter.dev
Switch, setState
1) ์ค์์น ๋ณ์ late๋ก ์ ์ธํ๊ณ , initState์์ ์ด๊ธฐ๊ฐ ์ค์
2) body์ Switch ์ถ๊ฐํด๋ณด๊ธฐ
Switch(
value: ์ค์์น ์ํ๊ฐ ๋ณ์,
onChanged: (value){
์ค์์น ์ํ๊ฐ ๋ณ์ = value;
}
)
3) ํ๋ฉด ํ์ธ - ์ค์์น๋ฅผ ํด๋ฆญํด๋ ์ํ๊ฐ ๋ณํ์ง ์๋๋ค!!!!!!!!
4) ์ค์์น ํด๋ฆญ ํ ๋ setState
5) ๋ค์ ์ ์ฅํ๊ณ ํ๋ฉด ํ์ธ - ํด๋ฆญํ๋ฉด ON/OFF๊ฐ ์ ์ ์ฅ๋์ด ์ถ๋ ฅ๋จ!
Switch, Button Color Change
1) ์ ์ญ ๋ณ์ late ์ ์ธ ๋ฐ initState()
๋ฒํผ ํด๋ฆญ ๋๋ ์ค์์น ํด๋ฆญ ํ ๋ ๋ง๋ค ๋ฒํผ ์นผ๋ผ ๋ณ๊ฒฝํ๊ธฐ
- Color ํ์ ์ ๋ฒํผ ์นผ๋ผ ๋ณ์ ์ ์ธ
- bool ํ์ ์ผ๋ก ์ค์์น์ ๋ฒํผ ์ํ ๋ณ์ ์ ์ธ
2) ํ๋ฉด ์ ํ - ๋ฒํผ๊ณผ ์ค์์น ์ถ๊ฐ
3) ํจ์ onClick()
๋ฒํผ์ ํด๋ฆญ ํ ๋๋ง๋ค, ๋ฒํผ์ ์ํ๋ฅผ true/false๋ก ๋ณ๊ฒฝํ์ฌ ์ ์ฅํ๋ค.
๊ทธ ์ ์ฅ ๊ฐ์ Switch์ ์ฌ์ฉ๋๋ onChanged ํจ์์ ๊ฐ์ด ๋ณด๋ด์ค๋ค.
4) ํจ์ onChanged(_buttonState)
onChange์์๋ ๋ฒํผ ์ํ๊ฐ์ ์ค์์น์ ์ํ๊ฐ์ผ๋ก ์ ์ฅํ๋ค.
๊ทธ๋ฆฌ๊ณ ์ค์์น์ ์ํ๊ฐ์ ๋ฐ๋ผ ๋ฒํผ ์นผ๋ผ๋ฅผ ๋ณ๊ฒฝํด์ค๋ค.
๐ ์ค์์น ํ๋ฉด์ถ๋ ฅ๊ณผ ๋ฒํผ์ ์นผ๋ผ๋ฅผ ๋ณ๊ฒฝํด์ฃผ์ด์ผ ํจ์ผ๋ก setState ํ์! ๐
5) ํ๋ฉด ํ์ธ
- ๋ฒํผ ํด๋ฆญ ์ ์ค์์น๋ ๊ณ์ on/off
- ์ค์์น๊ฐ off์ผ ๊ฒฝ์ฐ, ๋ฒํผ์ ์นผ๋ผ๋ blue
- ์ค์์น๊ฐ on์ผ ๊ฒฝ์ฐ, ๋ฒํผ์ ์นผ๋ผ๋ red
'๊ฐ๋ฐํ๊ธฐ > Flutter Start' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Flutter_15. List, Detail View, Message, Static ๋ณ์ (0) | 2023.05.08 |
---|---|
Flutter_14. Model, Class, List, Card, floatingActionButton (0) | 2023.05.08 |
Flutter_12. Package, Gesture, List, Image, Swipe, Button (0) | 2023.05.06 |
Flutter_11. Drawer, ListTitle, Navigator, body, class, Stateful (0) | 2023.05.05 |
Flutter_10. Drawer, ListView, UserAccountsDrawerHeader, AppBar IconButton (0) | 2023.05.04 |