Skip to content

Latest commit

 

History

History
63 lines (39 loc) · 1.26 KB

home.md

File metadata and controls

63 lines (39 loc) · 1.26 KB

Quick Start

Add to project

Add the following to your pubspec.yaml:

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

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

Initialize

Initializes Hive with a valid directory in your app files. You can also provide a subdirectory:

await Hive.initFlutter();

?> Use Hive.init() for non-Flutter apps.

Open a Box

All of your data is stored in boxes.

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

?> You may call box('testBox') to get the singleton instance of an already opened box.

Read & Write

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

import 'package:hive/hive.dart';

void main() async {
  //Hive.init('somePath') -> not needed in browser

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

  box.put('name', 'David');
  
  print('Name: ${box.get('name')}');
}

Video Tutorial

Learn the basics of using Hive in this well-made tutorial by Reso Coder.

<iframe id="ytplayer" type="text/html" data-src="https://www.youtube.com/embed/R1GSrrItqUs" class="video"/>