Form data disappears on scroll Flutter
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(
.....
Chaythanya Nair
Updated on December 04, 2022Comments
-
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 about 6 yearsI tried doing the same thing, but this doesn't save the entered values on scroll.
-
Hemanth Raj about 6 yearsWhere are you defining the TextEditingController
-
Chaythanya Nair about 6 yearsInside 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 about 6 yearsThanks that helped.