Home > Mobile >  In TextField( ) why we use " onSubmitted : " syntax?
In TextField( ) why we use " onSubmitted : " syntax?

Time:10-14

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,
              ),
            ),
          ),

CodePudding user response:

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

CodePudding user response:

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

  • Related