我可以存储Map< String,Object>在dart的“共享首选项”中? [英] Can i store a Map<String, Object> inside a Shared Preferences in dart?

查看:83
本文介绍了我可以存储Map< String,Object>在dart的“共享首选项”中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以将地图对象保存到共享的首选项中,这样我们就可以从共享的首选项中获取数据,而不必一直监听数据库。
实际上我想减少从Firebase下载的数据量。因此,我正在考虑一种解决方案,让监听器共享共享的首选项,并从共享的首选项中读取数据。

Is there a way that we could save a map object into shared preferences so that we can fetch the data from shared preferences rather than listening to the database all the time. actually i want to reduce the amount of data downloaded from firebase. so i am thinking of a solution to have a listener for shared prefs and read the data from shared prefs.

但是我看不到以颤振或飞镖的方式实现此目标的方法。

But i dont see a way of achieving this in flutter or dart.

如果有解决方法,请有人可以帮助我实现这一目标。

Please can someone help me to achieve this if there is a workaround.

非常感谢,
Mahi

Many Thanks, Mahi

推荐答案

如果将其转换为字符串,则可以存储它

If you convert it to a string, you can store it

import 'dart:convert';
...
var s = json.encode(myMap);
// or var s = jsonEncode(myMap);

json.decode(...) / jsonDecode(...)在加载时从字符串生成映射。

json.decode(...)/jsonDecode(...) makes a map from a string when you load it.

这篇关于我可以存储Map< String,Object>在dart的“共享首选项”中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆