A common approach when dealing with a database from an Object-Oriented Programming language (or OOP for short) is to deal with objects that mirror the structure of the tables in a database: this makes the code more reliable, easier to read, and helps prevent data inconsistencies.
Our shopping.db structure is extremely simple, so we'll just have to create two model classes, containing the same fields that are now in the tables, and a map method to simplify the process of inserting and editing data into the database. Follow these next steps to create a model class:
- We'll begin with the lists: create a new folder, called models.
- Inside the models folder, create a new file called shopping_list.dart.
- Inside the file, create a class called ShoppingList that will contain three properties: the id integer, the name String, and the priority integer...