在Flutter中存储对象列表 [英] Storing list of objects in Flutter

查看:104
本文介绍了在Flutter中存储对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,其中包含两个基本类,例如 Class1 Class2 .在 Class1 中,我将 List< Class2> 作为属性与其他属性一起存储.我的问题是,如果我在sqflite数据库中存储了 Class1 的某些对象,该如何存储 List< Class2> .有没有一种方法可以将 Class2 对象的列表存储在数据库的单个列中.

I am making an app, which contains two basic classes let's say Class1 and Class2. And in Class1 I stored List<Class2> as attribute with other attributes. My question is how to store List<Class2> if I store some object of Class1 in sqflite database. Is there a way that I can store a List of Class2 objects in a single column of the database.

推荐答案

您可以将其序列化为 json 并保存字符串.然后,当您阅读它时,可以将其解析回 Object

You can serialize it to json and save the string. Then when you read it you can parse it back to an Object

这篇关于在Flutter中存储对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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