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

Flutter_19. TextField, TextEditingController, dispose, onSubmitted, obscureText

uraon 2023. 5. 11. 07:00
728x90
๋ฐ˜์‘ํ˜•

์ด๋ฒˆ ํฌ์ŠคํŒ…์—๋Š” ํ…์ŠคํŠธํ•„๋“œ๋ฅผ ์ •๋ฆฌํ•ด๋ณด๋ ค ํ•œ๋‹ค.

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 ํด๋ž˜์Šค๊ฐ€ ์กด์žฌํ•œ๋‹ค. 

์ด๋ถ€๋ถ„์€ ์ถ”ํ›„ ๋”ฐ๋กœ ์ •๋ฆฌํ•˜๋ฉด์„œ ์ฒดํ‚นํ•  ์˜ˆ์ • ^-^* 

<์ถœ์ฒ˜ - api.flutter.dev>

 

 

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

 

 

 

๋ฐ˜์‘ํ˜•

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•