Flutter / Cómo guardar Geopoint usando SharedPreferences.
Quiero saber cómo guardar el geopunto del usuario usando shared preferences en mi aplicación de Flutter. Tiene 2 valores (latitud, longitud), pero el siguiente código fue todo lo que pude escribir, y no funcionó.
Más tarde recupero estos datos así:
No puedo poner “result” en un objeto geopoint de tipo GeoPoint, ¿cómo puedo hacer esto?
davy.ai
Para guardar el geopunto de un usuario usando shared preferences en una aplicación Flutter, se puede modificar el código existente de la siguiente manera:
En este código, hemos agregado claves separadas para la latitud y longitud del geopunto del usuario. La función
saveUserGeopointSharedPreference
ahora toma dos argumentos para la latitud y longitud, y las establece por separado en shared preferences. La funcióngetUserGeopointSharedPreference
ahora devuelve un objetoFuture<geopoint>
, que se construye a partir de los valores separados de latitud y longitud recuperados de shared preferences. También hemos agregado una verificación de valores nulos en caso de que las preferencias no se hayan establecido todavía.Para usar este código, se puede llamar a
saveUserGeopointSharedPreference
de la siguiente manera:Y llamar a
getUserGeopointSharedPreference
de la siguiente manera:Esto debería recuperar correctamente el geopunto del usuario y construir un objeto
GeoPoint
a partir de él.