I am trying to add multiple data to Sqflite in flutter but it’s not working.
For example I want to add a list of a Todo class.
Pls if there’s any help I’ll appreciate.
I tried writing a raw SQL to add the list of data but it didn’t work. All I was getting was bunch of errors.
2
Answers
actually there is no way you could insert all data by one function but you could do it with help of loops.
you could tiger loop while the length of the list and do the insert while its true! its too simple
To add a list of Todo class objects to Sqflite in Flutter, you can follow these steps:
DatabaseProvider
class from thesqflite
package. You can use this class to define methods for creating, opening, and updating the database.Todo
class that contains the data you want to store in the database. In this example, theTodo
class has four properties:id
,title
,description
, andisDone
.insertTodoList
method of theDatabaseHelper
class, create a batch object and use theinsert
method to insert eachTodo
object into the database. Finally, use thecommit
method to execute the batch.insertTodoList
method to insert a list of `Todo