Form data disappears on scroll Flutter

2,221

Solution 1

I have provided a solution for this in this link on github here. Yes, @HemanthRaj is absolutely right to use the TextEditingControllers but if you have so many fields inside a ListView this approach doesn't work as the ListView only loads the fields to be shown and purges these fields if scrolled out of view. I have explained a proper solution in the link provided. Please check it out and the solution works perfectly.

Regards, Mahi

Solution 2

For anyone who looking for a quick answer @Mahi's post: use SingleChildScrollView and Column instead of ListView:

Form(
  key: _formKey,
  child: SingleChildScrollView(
     child: Column(
     .....
Share:
2,221
Chaythanya Nair
Author by

Chaythanya Nair

Updated on December 04, 2022

Comments

  • Chaythanya Nair
    Chaythanya Nair over 1 year

    I have implemented a form with a few TextFormFields. When i scroll the form the TextFormFields that are out of the view loses entered data. There is a similar question already posted here. I have to no idea how to use a TextEditingController to save the state, since I am pretty new to Dart and Flutter. I even tried using FormFieldStatePersistor following this github repo. That also didn't work. Any ideas on how to solve the issue?

  • Chaythanya Nair
    Chaythanya Nair about 6 years
    I tried doing the same thing, but this doesn't save the entered values on scroll.
  • Hemanth Raj
    Hemanth Raj about 6 years
    Where are you defining the TextEditingController
  • Chaythanya Nair
    Chaythanya Nair about 6 years
    Inside the subclass of statefull widget. class _SignUpState extends State<SignUp> { .... static final TextEditingController _userID = new TextEditingController(); static final TextEditingController _firstName = new TextEditingController(); static final TextEditingController _lastName = new TextEditingController(); static final TextEditingController _email = new TextEditingController(); static final TextEditingController _password = new TextEditingController(); static final TextEditingController _confirmPassword = new TextEditingController(); .......
  • Chaythanya Nair
    Chaythanya Nair about 6 years
    Thanks that helped.