-1

Why do you use onSubmitted: option in TextField(), I wanted to make Textfield than the option onsubmited came and i didnt understand anything changes in the final result , can anyone plz explain it to me that why we use onSubmitted option?

this is my code:

TextField(
            style: TextStyle(
              color: Colors.lightBlueAccent,
            ),
            decoration: InputDecoration(
              labelText: "Password",
              labelStyle: TextStyle(
                color: Colors.grey,
              ),
              enabledBorder: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.grey.shade300,
                  width: 2,
                ),
                borderRadius: BorderRadius.circular(30),
              ),
              focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(
                  color: Colors.blue,
                  width: 2,
                ),
                borderRadius: BorderRadius.circular(30),
              ),
              prefixIcon: Icon(
                Icons.lock_outline,
              ),
            ),
          ),
Mou Biswas
  • 157
  • 2
  • 14

3 Answers3

0

onSubmitted uses for when you press enter key, which triggers the callBack function(like print or other function).

TextField(
              onSubmitted: (value){
                print(value);
              },
            ),

For more onSubmitted

Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
0

onSubmitted property called when the user indicates that they are done editing the text in the field.

Simply when user press Enter on keyboard and while using TextField, it calls onSubmitted, it provides the value of that TextField. Suppose, we don't have any TextEditingController or using onChanged and we can use setState method to assign the value here. I only prefer it when I just concern about final value.

For More onSubmitted

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

It is used to pull the focus manually to another widget at the time when the user is done using the TextField (when the user presses enter).

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 10 '23 at 11:26