【发布时间】:2020-09-07 11:32:50
【问题描述】:
我在 Flutter 应用程序中使用 shared_preferences 插件,我想在用户选择城市时保存数据。 但是当我尝试打印时,它只是说;
“SharedPreferences”未处理异常的实例:setState() 回调参数返回一个 Future
。 (即使我删除了我的 setState 部分,我也会在我的控制台中得到同样的错误)。
有人知道原因吗?
卡片小部件中的我的文字
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0),
child: Text(
snapshot.data.name,
style: TextStyle(fontSize: 16),
),
),
当点击我保存它的位置时
onTap: () {
setState(() async {
final country =
await SharedPreferences.getInstance();
String name;
name=snapshot.data.name;
country.setString('name', name);
print('here $country');
});
},
【问题讨论】: