Local Database
Learn to persist data with SQLite.
In this lesson, we’ll persist the cart data using SQLite. Using SQLite will require some knowledge of SQL. You can review the An Introductory Guide to SQL course on Educative.
This lesson uses the sqflite
plugin to create, read, update, and delete cart items and the path
package to manipulate paths.
You will work on the app below:
// Route constants const String productsOverviewRoute = '/'; const String productDetailRoute = '/product-detail'; const String cartScreenRoute = '/cart-screen'; const String settingsScreenRoute = '/settings-screen'; // Prefs Constants const prefStringKey = 'username'; const prefNumKey = 'phoneNumber'; const prefBoolKey = 'theme';
E-commerce app initial code
Adding dependencies
Add the sqflite
plugin to the pubspec.yaml
file. Locate # TODO-1: Add dependency
and add the dependency shown below:
Press + to interact
sqflite: ^2.0.2path: ^1.8.1
Note: Import the dependencies into the necessary files.
Defining constants
In the lib/utility/local_database.dart
file, locate // TODO-2: Add field constants
and define constants for the database name, database version, and the cart ...