【发布时间】:2021-08-17 05:16:26
【问题描述】:
我的应用程序出错了。我无法从 Flutter 中的共享性能中读取数据
我的代码
TextFormField(
enabled: false,
initialValue: Data.getData(key: 'phone_number'),
maxLength: 14,
keyboardType: TextInputType.phone,
textDirection: TextDirection.ltr,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.deepPurple),
),
suffixIcon: Icon(
Icons.phone_android_sharp,
color: Colors.deepPurple,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0)),
)),
我的 getData 函数
static getData({key}) async {
final perf = await SharedPreferences.getInstance();
var data = perf.getString(key);
print(data);
return data.toString();
}
【问题讨论】:
-
这能回答你的问题吗? What is a Future and how do I use it?
-
从共享首选项中获取数据是异步操作,请查看FutureBuilder
标签: flutter dart sharedpreferences