List<String> currentList =new List<String>();
void initState() {
super.initState();
currentList=[];
}
Future<Null> savePreferences(option,questionIndex) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
currentList.insert(questionIndex, option);
}
So basically what I am trying to do is save an option for a question at the specified index (I checked and the index is returned properly) in shared preferences. When it runs and I press the option, it returns to me the following error:
E/flutter ( 6354): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: RangeError (index): Invalid value: Valid alue range is empty: 0
The reason I am using the insert method and not the add method is because I want to essentially replace the value that is already stored at the index in the case that the user wants to overwrite their previous answer. Can someone help? Thanks