简体   繁体   English

使用 flutter_secure_storage 保存数据的列表文本......这可能吗?

[英]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.

相关问题 flutter_secure_storage中可以存储多少数据? - How much data can store in flutter_secure_storage? Flutter - 为什么/flutter_secure_storage 是安全的? - Flutter - Why/How is flutter_secure_storage secure? flutter 中的 flutter_secure_storage 和 shared_prefrences 有什么区别? 为什么 flutter_secure_storage 更安全? - What are the differences between flutter_secure_storage and shared_prefrences in flutter? Why is flutter_secure_storage more secure? 我将如何保持存储flutter_secure_storage的列表顺序? - How would I keep the order of the list stored flutter_secure_storage? 使用 flutter_secure_storage package 为 ios 创建构建存档时出现问题 - Problem creating a build archive for ios using flutter_secure_storage package 如何实现使用flutter_secure_storage包读写数据的流程【with Provider包】 - How to implement a process that uses flutter_secure_storage package to read and write the data [with Provider package] 无法解析配置 &#39;:flutter_secure_storage:classpath&#39; 的所有工件 - Could not resolve all artifacts for configuration ':flutter_secure_storage:classpath' flutter_secure_storage 究竟是什么以及它是如何工作的? - What is flutter_secure_storage exactly and how it works? 在我的场景中,哪个包更好 flutter_secure_storage 或 getx ? - Which package is better flutter_secure_storage or getx in my scenario? Flutter 找不到所需的 package flutter_secure_storage/linux/CMakeLists.txt:14 - Flutter A required package was not found flutter_secure_storage/linux/CMakeLists.txt:14
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM