我正试图找到一种方法来检索数据从sharedpreference StringList..
我的控制器中有这些textditingcontrollers
late TextEditingController displayname;
late TextEditingController jobtitle;
late TextEditingController about;
late TextEditingController email;
late TextEditingController address;
late List<String> info;
MyServices myServices = Get.find();
在用户移动到下一页之前,我将每个on控制器的内容保存在sharedPreference StringList上:
myServices.sharedPreferences.setStringList("profileinfo", [
displayname.text,
jobtitle.text,
about.text,
email.text,
address.text,
]);
这里出现错误,当我最初尝试检索保存的数据时(如果用户再次返回此页面)
void onInit() {
imagePath = "";
if (myServices.sharedPreferences.getStringList("profileinfo") == null) {
info = [];
displayname = TextEditingController();
jobtitle = TextEditingController();
about = TextEditingController();
email = TextEditingController();
address = TextEditingController();
} else {
info = (myServices.sharedPreferences.getStringList("profileinfo"))!;
displayname = TextEditingController(info[0]); // Here is the error
jobtitle = TextEditingController();
about = TextEditingController();
email = TextEditingController();
address = TextEditingController();
}
super.onInit();
}
错误提示"太多位置参数:期望0,但发现1。尝试删除额外的位置参数,或为命名参数指定名称。">
我尝试了很多方法,包括使用(.?)或(!)..
您填写TextEditingController
的方式错误,您忘记指定text
,请尝试:
displayname = TextEditingController(text: info[0]);