[英]Save List Texst of data using flutter_secure_storage ... is it possible?
iam using flutter_secure_storage in my Flutter app ...我在我的 Flutter 应用程序中使用flutter_secure_storage ...
iam Saving data as a key with it is take a value of String like this : iam 将数据保存为一个键,它采用这样的字符串值:
await storage.write(key: 'currntUserID', value: 'userid');
and iam reding it like this :我像这样编辑它:
urrntUserID = (await storage.read(key: 'currntUserID'))!;
but urrntUserID
it just a String !但
urrntUserID
它只是一个字符串!
but what if i have a List of Strings ... is there any way to save thiam all in the storage ?但是如果我有一个字符串列表怎么办……有什么办法可以将 thiam 全部保存在存储中?
What i need is like if i have :我需要的是,如果我有:
List<String> listviewerbulderstring = ['a1','a2','a3']
What i need to do is like call the array to = the Saved array in the storeg somthing like this :我需要做的是将数组调用为 = 存储中的 Saved 数组,如下所示:
List<String> listviewerbulderstring = (await storage.read(key: 'listofiteams'))!;
is this even possible ?这甚至可能吗? or there is better way to do this ?
或者有更好的方法来做到这一点?
This can be achieved by using JSON serialization like so:这可以通过使用 JSON 序列化来实现,如下所示:
void myFunction() async {
const storage = FlutterSecureStorage();
List<String> listviewerbulderstring = ['a1','a2','a3'];
await storage.write(key: 'listofitems', value: jsonEncode(listviewerbulderstring));
String? stringofitems = await storage.read(key: 'listofitems');
List<dynamic> listofitems = jsonDecode(stringofitems!);
print(listFromJson);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.