sqlite 如何在Flutter中向Sqflite添加数据列表

nx7onnlm  于 2023-04-30  发布在  SQLite
关注(0)|答案(1)|浏览(185)

我试图添加多个数据到Sqflite在Flutter,但它不工作.
例如,我想添加一个Todo类的列表。
如果有任何帮助,我将不胜感激。
我尝试编写一个原始SQL来添加数据列表,但它不起作用。我得到的只是一堆错误。

tf7tbtn2

tf7tbtn21#

实际上,你不可能通过一个函数插入所有数据,但你可以在循环的帮助下做到。你可以在列表的长度的时候循环,并在它为真的时候插入!它太简单了

List<Todo>todos=[Todo('example'),Todo('example'),Todo('example'),Todo('example')];
//here should be the db provide class
for(Todo iteam in todos){
   // do the insert functionality
   // here try the way you insert single todo in db
   db.insert(iteam.toJson())
}

相关问题