Add the sqflite package in the pubspec.yaml dependencies. Add the path_provider package too, we will use it for the join function.
Open the database
I will use a custom class with the name “Task” to store in the database. It has some attributes, a constructor to initialize the class from a map, and a function to convert the class to a map.
We can open the database with the openDatabase function.
The first argument is the path to the database
onCreate will be executed when we create the database, that is to say the first time we call openDatabase with this path.
onOpen will be executed when the database is opened. The first time we call openDatabase, onOpen will be also called after onCreate.
Add element
We can add an element with the insert function:
The insert function returns the id the database assigns to the element. We can retrieve that id and assign it to the object.