Skip to content
Lightweight and blazing fast key-value database written in pure Dart.
Branch: master
Clone or download
Latest commit b59a6af Nov 13, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update test.yml Nov 13, 2019
example Move hive to root Nov 13, 2019
lib Fix build Nov 13, 2019
test Fix build Nov 13, 2019
.gitattributes Add flutter getting started (#67) Oct 3, 2019
.gitignore Add drawing_app example Aug 22, 2019 Renamed Hive.openBoxFromBytes() Nov 13, 2019
LICENSE License Oct 26, 2019 Move hive to root Nov 13, 2019
analysis_options.yaml Move hive to root Nov 13, 2019
pubspec.yaml Move hive to root Nov 13, 2019

Dart CI Codecov Core version

Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask.

Flutter Web Demos 🕸️


Cross-platform ⚡

  • Runs on desktop, mobile & in browser
  • Very good performance (see benchmark)

Easy to use ❤️

  • Keys are of type String or uint32 and values are arbitrary objects
  • The basic operations are put(key, value), get(key), delete(key)
  • Strong encryption built in

Lightweight 🎈

  • Small runtime
  • Small disk space consumption
  • NO native dependencies


Read 1000 entries Write 1000 entries
SharedPreferences is on par with Hive when it comes to read performance. SQLite performs much worse. Hive greatly outperforms SQLite and SharedPreferences when it comes to writing or deleting.

This benchmark was performed on a Oneplus 6T with Android Q. All entries are read and written one after another. You can run the benchmark yourself.

Getting started

To get started using Hive in a Flutter project, add the following dependencies to your pubspec.yaml. Use the latest version instead of [version].

Core version Generator version Hive Flutter version Build runner version

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

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


You can use Hive just like a map. It is not necessary to await Futures.

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

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

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

print('Name: $name');

Store objects

Hive not only supports primitives, lists and maps but also any Dart object you like. You need to generate a type adapter before you can store objects.

class Person extends HiveObject {

  String name;

  int age;

Extending HiveObject is optional but it provides handy methods like save() and delete().

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

var person = Person() = 'Dave'
  ..age = 22;

print(box.getAt(0)); // Dave - 22

person.age = 30;;

print(box.getAt(0)) // Dave - 30

Hive ❤️ Flutter

Hive was written with Flutter in mind. It is a perfect fit if you need a lightweight datastore for your app. After adding the required dependencies to your pubspec.yaml, you are able to use Hive in your project:

import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';

class SettingsPage extends StatelessWidget {
  Widget build(BuildContext context) {
    return WatchBoxBuilder(
      builder: (context, box) {
        return Switch(
          value: box.get('darkMode'),
          onChanged: (val) {
            box.put('darkMode', val);

Boxes are cached and therefore fast enough to be used directly in the build() method of Flutter widgets.


The work on Hive has just started. If you want to contribute, it would be amazing if you helped me with one of these:

  • Good test coverage
  • Many examples, especially for Flutter
  • Benchmarks and comparison
  • Finalize API
  • Even more tests
  • Queries
  • Improve documentation
  • Write binary format spec
  • You can never have enough tests


Copyright 2019 Simon Leier

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.