1

What is the difference between onSubmitted vs onEditingComplete in Flutter textField widgets?

I mean, onSubmitted already passes us the value the user has entered which we can use when submitting is done. Why need an onEditingComplete property?

I also came across this stackoverflow post

According to the top answer of this post, onEditingComplete is used to determine whether the keyboard should be hidden or kept after the user submits the data. If this is the case, why would flutter go leaps and bounds to have a property called onEditingComplete that ACCEPTS A FUNCTION? They could simply have a property like hideKeyboardAfterEditing which accepts either true or false.

(I might have understood the mention Stack Overflow post wrong here. But this is how my mind grasped it)

Can someone please help me understand this?

Thanks

gfit21x
  • 141
  • 9

1 Answers1

1

Both are technically the same but onEditingComplete will not lower the onscreen keyboard (example : chat apps) and onSubmitted will lower the onscreen keyboard and additionally onSubmitted will return the textfield value.

Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30
  • thank you for the response. One thing I would like to clarify from you is, in the top answer in the Stackoverflow post I have mentioned they mention `But if we override the onEditingComplete callback to an empty function, it will stop the default behaviour and not hide the keyboard.`. This implies that the soft keyboard is kept only if we pass an empty function to the `onEditingComplete` property. But your answer says that soft keyboard always stays. This seems to be a conflict to me. Can you please clarify this for me? Thanks. – gfit21x Oct 17 '21 at 14:08
  • 1
    The `onSubmitted` will definitely shift focus to the next widget but `onEditingComplete` will behave in 2 ways based on the actions. 1. Completion action (send, go, submit) then focus is given up. 2. non completion action (next, previous) then focus is not given up. – Kaushik Chandru Oct 17 '21 at 14:19