Flutter widget rebuilding when TextField widget clicked

When we click on TextField then build() method is called automatically by flutter so your all object is recreate which initialise within build() method.

That's why always create global variable which is used in Form() like :

final emailController =  TextEditingController();
final _formKey = GlobalKey<FormState>();

if your screen depends on MediaQuery or at least having one widget depenig on MediaQuery, the keyboard popup changes the size of your screen, which triggers mediaQuery and causing rebuilds...in this case avoid using mediaQuery, Instead get your dimensions using (sizer package) https://pub.dev/packages/sizer


you have to declare _formKey as static outside of build method.

Tags:

Dart

Flutter