【发布时间】:2021-12-31 18:19:33
【问题描述】:
我想知道如何在我的颤振应用中使用共享偏好来保存用户的地理点。它有 2 个值(纬度,经度),但我只能写以下代码,但没有用。
static String sharedPreferenceUserGeopointKey = "USERGEOPOINTKEY";
static Future<bool> saveUserGeopointSharedPreference(var geopoint) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return await preferences.setDouble(
sharedPreferenceUserGeopointKey, geopoint);
}
后来我像这样检索这些数据;
static Future<dynamic> getUserGeopointSharedPreference() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
double mylat =
preferences.getDouble(sharedPreferenceUserGeopointLatKey);
double mylong =
preferences.getDouble(sharedPreferenceUserGeopointLongKey);
return true;
}
bool result = await getUserGeopointSharedPreferences();
GeoPoint geopoint = result;
我无法将result 放入 GeoPoint 类型的地理点对象中,我可以这样做吗?
【问题讨论】: