Challenge: Local Storage with the Hive Library
Test your understanding of local data persistence in Flutter.
In this challenge, you’ll save data locally using Hive.
Goal
The goals of this challenge include:
- Learn to use official documentation to implement a package.
- Use the Hive package to persist cart items locally in your mobile app.
Specs
When the user adds an item to the cart, it’s added successfully and is persisted on app restart.
Starter code
Before you begin the challenge, look at the starter code below.
Note: Run the app after adding the necessary packages.
// 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';
Hive challenge starter code
Challenges
You can refer to the official Hive documentation to go through example implementations.
Challenge 1: Add Packages
In this challenge, you will add the necessary packages to get started with Hive.
- Locate
#