Flutter_19. TextField, TextEditingController, dispose, onSubmitted, obscureText
์ด๋ฒ ํฌ์คํ ์๋ ํ ์คํธํ๋๋ฅผ ์ ๋ฆฌํด๋ณด๋ ค ํ๋ค.
TextField ๊ด๋ จ ๋ด์ฉ์ ์๋ ๋งํฌ ์ฐธ๊ณ :)
https://api.flutter.dev/flutter/material/TextField-class.html
TextField class - material library - Dart API
A Material Design text field. A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard. The text field calls the onChanged callback whenever the user changes the text in the field. If the user indicates that they ar
api.flutter.dev
TextField, InputDecoration, obscureText
1) ๊ธฐ๋ณธ ์์ ์คํ
ํ๋ฌํฐ ์ฌ์ดํธ์ ์๋ ๊ธฐ๋ณธ ์์ ๋ฅผ ์คํํด๋ณด์๋ค.
InputDecoration์ OutlineInputBorder๋ฅผ ์ฌ์ฉํ์ฌ ํ ๋๋ฆฌ ํ๋๋ฅผ ๋ผ์ธ์ผ๋ก ๊ฐ์ธ์ฃผ๊ณ , ๊ทธ ์์ ๋ ์ด๋ธ ๋ฌธ๊ตฌ๊ฐ ์ถ๊ฐ๋์๋ค.
TextField
- obscureText : ๋ฌธ์ ์จ๊น ์ฒ๋ฆฌ(ex ๋น๋ฐ๋ฒํธ ์ ๋ ฅ)
- decoration : InputDecoration(border, labelText)
// Ex01.(api.flutter.dev)
TextField(
obscureText: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
2) ๊ฒฐ๊ณผ ํ์ธ
obscureText: true | obscureText: false |
![]() |
![]() |
๐ obscureText
onSubmitted, TextEditingController, dispose
1) ๋๋ฒ์งธ ์์ ์คํ
TextField์์ ๊ฐ์ ์ฝ๋ ๋ฐฉ๋ฒ์ onSubmitted ์ฝ๋ฐฑ์ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค.
์ด ์ฝ๋ฐฑ์ ์ฌ์ฉ์๊ฐ ํธ์ง์ ์๋ฃํ์ ๋ onChanged ์ดํ ํธ์ถ๋๋ฉฐ, ํ ์คํธ ํ๋์ ํ์ฌ ๊ฐ์ด ์ ์ฉ๋๋ค.
โ onChanged : input ์นธ์ ๋ด์ฉ์ด ๋ฐ๋ก๋ฐ๋ก ๋ณ๊ฒฝ๋ ๋
โ onSubmitted : ํค๋ณด๋์ ์ ๋ ฅ์๋ฃ๋ฅผ ํด๋ฆญ ํ์ ๋
https://api.flutter.dev/flutter/material/TextField/onSubmitted.html
onSubmitted property - TextField class - material library - Dart API
ValueChanged ? onSubmitted final Called when the user indicates that they are done editing the text in the field. By default, onSubmitted is called after onChanged when the user has finalized editing; or, if the default behavior has been overridden, after
api.flutter.dev
2) TextEditingController ์ ํ
โ dispose ํจ์ ์ค๋ฒ๋ผ์ด๋ฉ โ
์์ ฏ์ด dispose๋ ๋, ์ปจํธ๋กค๋ฌ๋ ๊ฐ์ด dispose๋๋๋ก ํด์ผํ๋ค. ๋ฐ๋์!!
3) TextField ์์ฑ
TextField
- controller : TextEditingController
- onSubmitted : (String value) async{ await... }
โ ํ ์คํธํ๋๋ ์ปจํธ๋กค๋ฌ๊ฐ ์๊ธฐ ๋๋ฌธ์ setState๊ฐ ํ์ ์๋ค!!!
// Ex02.(api.flutter.dev)
TextField(
controller: _controller,
onSubmitted: (value) async{
// ----
await showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: const Text('Thsnks!'),
content: Text(
'You typed "$value", which has length ${value.characters.length},'
),
actions: [
TextButton(
onPressed: () {
// ----
Navigator.pop(context);
},
child: const Text('OK'),
),
],
);
}
);
},
),
4) ๊ฒฐ๊ณผ ํ์ธ
TextFormField, onEditingComplete
TextField์ ๋ณ๊ฐ๋ก TextFormField ํด๋์ค๊ฐ ์กด์ฌํ๋ค.
์ด๋ถ๋ถ์ ์ถํ ๋ฐ๋ก ์ ๋ฆฌํ๋ฉด์ ์ฒดํนํ ์์ ^-^*
https://api.flutter.dev/flutter/material/TextFormField-class.html
TextFormField class - material library - Dart API
A FormField that contains a TextField. This is a convenience widget that wraps a TextField widget in a FormField. A Form ancestor is not required. The Form simply makes it easier to save, reset, or validate multiple fields at once. To use without a Form, p
api.flutter.dev
https://api.flutter.dev/flutter/material/TextField/onEditingComplete.html
onEditingComplete property - TextField class - material library - Dart API
VoidCallback? onEditingComplete final Called when the user submits editable content (e.g., user presses the "done" button on the keyboard). The default implementation of onEditingComplete executes 2 different behaviors based on the situation: When a comple
api.flutter.dev