์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- vscode
- icon
- switch
- image
- POP
- drawer
- list
- sizedbox
- textField
- Webflow
- button
- ontap
- GestureDetector
- ElevatedButton
- InputDecoration
- slider
- TextEditingController
- Routing
- navigator
- Snackbar
- AlertDialog
- figma
- Scaffold
- dart
- PushNamed
- stateful
- flutter
- scaffoldmessenger
- AppBar
- FloatingActionButton
- Today
- Total
์ฌ๋ฐ๋๊ฑฐ๐
Flutter_22. CardList, Add Card, TextField, TextArea, Clear Button ๋ณธ๋ฌธ
Flutter_22. CardList, Add Card, TextField, TextArea, Clear Button
uraon 2023. 5. 14. 07:00์~์ ํฌ์คํ ์ ์ด์ด Card List์ Card๋ฅผ ์ถ๊ฐํ๋ ํ๋ฉด์ ๊ตฌํํด๋ณด๋๋ก ํ๊ฒ ๋ค.
์ด์ ๋ด์ฉ์ ์๋ ๋งํฌ ์ฐธ๊ณ !
2023.05.08 - [๊ฐ๋ฐํ๊ธฐ] - Flutter_15. List, Detail View, Message, Static ๋ณ์
2023.05.10 - [๊ฐ๋ฐํ๊ธฐ] - Flutter_18. DialogAlert, Slider Function, Size, List, Switch
Figma, Function Check
1) ๊ตฌํํด์ผํ ํ๋ฉด ์ฒดํฌ
๐ฟ ์ฒดํฌ ํญ๋ชฉ
1) TextField : clear Button
2) TextArea : TextField + maxLines
3) Image
2) card_add.dart ํ์ผ์ AppBar์ Scaffold ์นผ๋ผ ์ค์
3) ๋ณ์ ์ ํ
์ด๋ฒ ํฌ์คํ ์์ Image๋ ์ฐ์ 1๊ฐ ๊ณ ์ ์ผ๋ก ๋๊ณ , ์นด๋ ๋ฆฌ์คํธ ์ถ๊ฐ ๊ธฐ๋ฅ์ ๊ตฌํํ๊ฒ ๋ค.
๋ค์์๋ picker๋ก ์ ํ, ๊ทธ ๋ค์์๋ upload ์์ผ๋ก ๋ณต์ต ๋ฐ ๊ณต๋ถํด๋ณด๋ ค ํ๋ค.
4) ํค๋ณด๋ ๋ด๋ฆฌ๊ธฐ FocusScope ์ค์
TextField, Clear Button
1) body์ TextField ์ถ๊ฐ
ํ ์คํธํ๋ ๋ด์ ์๋ Clear Button์ ์์ด์ฝ ๋ฒํผ์ผ๋ก ๊ตฌํํ๋ค.
Icon Button ํด๋ฆญ ์ ์ด๋ฒคํธ๋ก ํด๋น ํ ์คํธํ๋์ TextEditingController๋ฅผ clear() ํด์ฃผ๋ฉด ํ ์คํธํ๋ ๊ฐ์ด ์ด๊ธฐํ ๋๋ค.
โ TextField
- controller : TextEditingController
- keyboardType : TextInputType
- decoration : InputDecoration
- style : TextStyle
โ InputDecoration
- border : OutlineInputBorder() → borderSide๋ก ๋๊ป ์ค์
- contentPadding : EdgeInsets.symmetric ๋ก ๊ฐ๋ก ์ธ๋ก ํจ๋ฉ ๊ฐ๊ฒฉ ์ค์
- label : Text
- suffix : IconButton() → ์ปจํธ๋กค๋ฌ.clear()๋ก clear ๋ฒํผ ๊ตฌํ
TextField(
controller: _controllerArtName,
keyboardType: TextInputType.text,
decoration: InputDecoration(
border: const OutlineInputBorder(
borderSide: BorderSide(width: 0.5),
),
contentPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
label: const Text('Art Name'),
suffix: IconButton(
onPressed: () => _controllerArtName.clear(),
icon: const Icon(Icons.close)
),
),
style: const TextStyle(
fontSize: 18
),
),
Textarea : TextField, MaxLines
1) body์ TextField๋ก TextArea ๋ง๋ค๊ธฐ
ํ ์คํธํ๋์ maxLines์ ์ค์ ํด ์ฃผ๋ฉด, TextArea์ฒ๋ผ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
maxLength๋ 100์ ๋๋ก ์ค์ ํ์ฌ ๋๋ฌด ๊ธด ๋ฌธ์ฅ์ด ๋ค์ด๊ฐ์ง ๋ชปํ๋๋ก ํ์๋ค.
๊ทธ๋ฆฌ๊ณ , ์ด๋ฒ์๋ clear Button ์์ญ์ ์กฐ๊ฑด์ ์ถ๊ฐํด๋ณด์๋ค. isEmpt์ด๋ฉด, ๋ฒํผ์ ์ถ๋ ฅํ์ง ์๋๋ค.
TextField(
maxLines: 3,
maxLength: 100,
controller: _controllerArtContents,
keyboardType: TextInputType.text,
decoration: InputDecoration(
border: const OutlineInputBorder(
borderSide: BorderSide(width: 0.5),
),
contentPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
label: const Text('Art Contents'),
suffix: _controllerArtContents.text.isEmpty
? null
: IconButton(
onPressed: () => _controllerArtContents.clear(),
icon: const Icon(Icons.clear)
),
),
style: const TextStyle(
fontSize: 18
),
),
Image, Button, Navigator.pop
1) ์ด๋ฏธ์ง SizedBox > Column์ผ๋ก ์์ญ ์ก์์ ์ถ๋ ฅ
// --- Image Area ---
SizedBox(
width: 350,
height: 350,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
_addImagePath,
width: 250,
height: 250,
),
],
),
),
const SizedBox(
height: 20,
),
2) ๋ฒํผ ํํ ๋ง๋ค๊ณ ํ๋ฉด ํ์ธ
์ฐ์ , ๊ธฐ๋ณธ ์ ํ ์ผ๋ก Navigator.pop(context)๋ฅผ ๋ฃ์๋ค.
๋ฒํผ์ ํด๋ฆญํ๋ฉด, ์ฐ์ ํด๋น ํ๋ฉด์ pop๋๊ณ ๋ค์ ์๋ ํ๋ฉด(List)์ด ๋ณด์ฌ์ง๋ค.
// --- Button Area ---
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: (){
// --------
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 134, 98, 243),
minimumSize: const Size(150, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
)
),
child: const Text('Save')
),
const SizedBox(
width: 20,
),
ElevatedButton(
onPressed: (){
// --------
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 134, 98, 243),
minimumSize: const Size(150, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
)
),
child: const Text('Cancel')
),
],
),
Add List Function
1) ํ ์คํธ ํ๋ 2๊ฐ ๋ชจ๋ Empty๊ฐ ์๋ ๊ฒฝ์ฐ, addList ํจ์ ํธ์ถ
2) addList ํจ์
Static ๋ณ์์ ์ ๋ ฅ๊ฐ์ ๋ชจ๋ ๋ด์์ค๋ค.
3) card_list.dart ํ์ผ์ .then ์ถ๊ฐ
Add Card ํ๋ฉด์ด pop๋๋ฉด, ์๋ ํ์ํด๋ ~~pushNamed(context, '/add')์ฌ๊ธฐ์ ๋ถํฐ ๋ค์ ์์ ๋๋ค.
์ด๋ถ๋ถ์ .then์ ์ถ๊ฐํด์ฃผ์. ๋ค๋ ์์ ์ด๋ป๊ฒ ํ ๊ฒ ์ธ์ง๋ฅผ ์ ์ํด์ฃผ๋ ๊ฒ์ด๋ค.
๋ฐ์ดํฐ๋ฅผ ๋ฆฌ์คํธ์ ์ถ๊ฐํ ๊ฒ์์ผ๋ก, rebuildData() ํจ์๋ฅผ ๋ง๋ค์ด ์ฌ์ฉ ํ ๊ฒ์์ ์ ์ด์ฃผ์.
4) rebuildData ํจ์ ๋ง๋ค๊ธฐ
setState๋ก List.add(ArtCard)
ArtCard์ ๊ฐ๋ค์ ๋ชจ๋, Static์ ์ ์ฅํด๋์ ๊ฐ๋ค๋ก ๋ด์์ค๋ค.
// Func
rebuildData(){
setState(() {
artcardList.add(ArtCard(
imagePath: Message.imagePath,
artName: Message.artName,
artContents: Message.artContents));
});
}
Add List ์งํ ์ฌ๋ถ ์ฒดํฌ
์์ ์ฝ๋๊น์ง๋ง ์คํํ๋ฉด, Static์ Message ๊ฐ๋ค์ด ๊ณ์ ๋จ์ ์์ด์
Add Card ํ๋ฉด์ ์ง์ ํ๋ค๊ฐ ๋ค์ List ํ๋ฉด์ผ๋ก ๋์๊ฐ๊ธฐ๋ง ํ๋ฉด, Card๊ฐ ๊ณ์~~ ์ถ๊ฐ๋๋ ์๋ฌ๊ฐ ์๋ค.
์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด, Add List ์งํ ์ฌ๋ถ๋ฅผ ์ฒดํฌํ๋ bool ํ์ Static ๋ณ์๊ฐ ํ๋ ๋ ํ์ํ๋ค.
1) Message.dart ํ์ผ์ Static ๋ณ์ "action" ์ถ๊ฐ
2) card_add.dart ํ์ผ์ ์๋ addList() ํจ์ ์์, ๋ฆฌ์คํธ๊ฐ ์ถ๊ฐ๋๋ค๋ ์๋ฏธ๋ก action์ true ๊ฐ์ผ๋ก ์ถ๊ฐ
3) card_list.dart ํ์ผ์ ์๋ rebuildData() ํจ์์์ ์กฐ๊ฑด๋ฌธ ์ถ๊ฐ
action์ด true์ผ ๊ฒฝ์ฐ์๋ง setState๋ก ๋ฆฌ์คํธ์ ๋ฐ์ดํฐ ์ถ๊ฐํด์ฃผ์.
์ถ๊ฐ ์๋ฃ ํ์๋ action ๊ฐ์ false๋ก ๋ณ๊ฒฝํด์ฃผ์ด, ์ค๋ณต์ผ๋ก ๊ณ์ ์นด๋๊ฐ ๋ฑ๋ก๋๋ ์๋ฌ๋ฅผ ํด๊ฒฐ! :)
4) ์ ์ฅํ๊ณ ํ๋ฉด ์ต์ข ํ์ธ
1) ์นด๋ ์ด๋ฆ๊ณผ ๋ด์ฉ, ์ด๋ฏธ์ง ์ ํ ํ [Save] >> ๋ฆฌ์คํธ์ ์นด๋ ์ถ๊ฐ
2) ์นด๋ ์ด๋ฆ๋ง ์ ๊ณ [Save] >> ๋ฆฌ์คํธ ์ถ๊ฐ ์์
3) [์ทจ์] ๋๋ [<]๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ >> ๋ฆฌ์คํธ ์ถ๊ฐ ์์
'๊ฐ๋ฐํ๊ธฐ > Flutter Start' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Flutter_23. Add Card, Cupertino, Picker (0) | 2023.05.15 |
---|---|
Flutter_21. FloatingActionButton, extend, Scaffold, body (0) | 2023.05.13 |
Flutter_20. TextField with Button, keyboardType, FocusScope, SnackBar (0) | 2023.05.12 |
Flutter_19. TextField, TextEditingController, dispose, onSubmitted, obscureText (0) | 2023.05.11 |
Flutter_18. DialogAlert, Slider Function, Size, List, Switch (0) | 2023.05.10 |