【发布时间】:2020-10-03 15:51:45
【问题描述】:
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);
}
所以基本上我要做的是在共享首选项中的指定索引处保存一个问题的选项(我检查并正确返回了索引)。当它运行并且我按下选项时,它返回给我以下错误:
E/flutter ( 6354): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: RangeError (index): Invalid value: Valid alue range is empty: 0
我使用 insert 方法而不是 add 方法的原因是因为我想在用户想要覆盖他们之前的答案的情况下替换已经存储在索引中的值。有人可以帮忙吗?谢谢
【问题讨论】:
标签: flutter dart sharedpreferences