![](/img/trans.png)
[英]How to save and get a list of lists using Shared preferences in dart/flutter
[英]flutter/ how to save geopoint using shared preferences
我想知道如何在我的 flutter 應用程序中使用共享偏好來保存用戶的地理點。 它有 2 個值(緯度,經度),但以下代碼是我能寫的全部,但沒有用。
static String sharedPreferenceUserGeopointKey = "USERGEOPOINTKEY";
static Future<bool> saveUserGeopointSharedPreference(var geopoint) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return await preferences.setDouble(
sharedPreferenceUserGeopointKey, geopoint);
}
后來我這樣稱呼這個function。
saveUserGeopointSharedPreference(mylatlong);
如何使用共享首選項保存具有 2 個值(緯度、經度)的地理點?
您需要使用不同的鍵調用兩次 setDouble。
或者嘗試使用共享首選項 class 的 setStringList() 方法。
在這種情況下,您需要從雙緯度、對數度更改為列表字符串。
static String sharedPreferenceUserGeopointLatitudeKey = "USERGEOPOINT_LATITUDE_KEY";
static String sharedPreferenceUserGeopointLogitudeKey = "USERGEOPOINT_LONGITUDE_KEY";
static Future<bool> saveUserGeopointSharedPreference(var lat, var long) async {
SharedPreferences preferences = await SharedPreferences.getInstance();
await preferences.setDouble(
sharedPreferenceUserGeopointLatitudeKey, lat);
await preferences.setDouble(
sharedPreferenceUserGeopointLogitudeKey, long);
return true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.