Skip to content

X-Wei/docs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

description
Lightweight and blazing fast key-value database written in pure Dart.

Hive Documentation

Add Hive to project

Add the following to your pubspec.yaml. Use the latest version instead of [version].

Core version Generator version Flutter version Build runner version

dependencies:
  hive: ^[version]
  hive_flutter: ^[version]

dev_dependencies:
  hive_generator: ^[version]
  build_runner: ^[version]

Initialize

Before you can use Hive in your app, you must initialize it. This only has to be done once.

Give Hive a directory where it can store its files. It is recommended to use an empty directory. Each box will have it's own .hive file in the Hive-home directory.

Hive.init('path/to/hive');

If you use a directory outside your app files, make sure to request runtime permission on Android.

In the browser you don't have to call Hive.init().

Open a Box

All of your data is stored in boxes.

var box = await Hive.openBox('testBox');

{% hint style="info" %} You may call box('testBox') to get the singleton instance of an already opened box. This will save one async call. {% endhint %}

Read & Write

Hive supports all primitive types, List, Map, DateTime and Uint8List. Any object can be can stored using TypeAdapters.

box.put('name', 'David');

var name = box.get('name');

print('Name: $name');

Video Tutorial

{% embed url="https://www.youtube.com/watch?v=R1GSrrItqUs" caption="Learn the basics of using Hive in this well made tutorial by Reso Coder." %}

About

Documentation of the Hive database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published