0

Hi i am new to flutter but i was wondering how i could save a list of TextEditingController in shared preferences and how i can display a value from the list for example input 1.

 var list = new List<TextEditingController>();

  final TextEditingController Input1 = new TextEditingController();
  final TextEditingController Input2 = new TextEditingController();
  final TextEditingController Input3 = new TextEditingController();

Register Screen

asdsd
  • 129
  • 1
  • 1
  • 6
  • Does this answer your question? [How to save List to SharedPreferences?](https://stackoverflow.com/questions/28107647/how-to-save-listobject-to-sharedpreferences) – Blundell Jan 28 '20 at 16:18

1 Answers1

0

Sure, you can use SharedPreferences to store any String you want. Assuming you are using it in a widget's state:

 var list = new List<TextEditingController>();

 final TextEditingController input1 = new TextEditingController();
 final TextEditingController input2 = new TextEditingController();
 final TextEditingController input3 = new TextEditingController();

 void initState(){
   super.initState();
   SharedPreferences.getInstance().then((prefs){
     input1.text =  prefs.getString('input1');
     input2.text =  prefs.getString('input2');
     input3.text =  prefs.getString('input3');
   });
 }

 void _saveInputs(){
   SharedPreferences.getInstance().then((prefs){
     prefs.setString(input1.text);
     prefs.setString(input2.text);
     prefs.setString(input3.text);
   });
 }

Have in mind that you need to call _saveInputs() in order to save the changes, however, I'm not sure why you want to do this, but here you have it.

Miguel Ruivo
  • 16,035
  • 7
  • 57
  • 87