Persisting data using HiveDB
HiveDB is one of the other popular choices for persisting data in Flutter. As it’s written completely in Dart, it supports the web natively. In this section, using HiveDB, we will build a watchlist feature. We will allow users to add any course of their choice to the watchlist and we will add a watchlist section where users can view a list of their watched courses. We are using HiveDB for this feature as it is designed to handle a bit more complex data than SharedPreferences. Also, HiveDB has an easier API to implement. We can use HiveDB to store and load the theme mode that we implemented in the previous section as well without any issues.
Setting Up HiveDB
Follow these steps to set up HiveDB:
- We will start by adding the dependency to our
pubspec.yaml
file. To use HiveDB with Flutter, we will add thehive
andhive_flutter
packages as the dependency. Underdependencies
inpubspec.yaml
, add the following:dependencies: &...