TextEditingController makes widget lose its previous state

Posted by Jessica Taylor | Updated on

TextEditingController makes widget lose its previous state. The explanation for the observed behavior is the following:

CupertinoTextField uses an internal TextEditingController for which the framework automatically sets an AutomaticKeepAlive. This keepAlive is responsible for keeping the state.

If you use your own controller, you are in charge of attaching the AutomaticKeepAlive because the framework doesn’t do it for you.

The following snippet adds the keepAlive to your code:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers