Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiveObject does not have key when loaded lazy #112

PauloMelo opened this issue Nov 1, 2019 · 2 comments


Copy link

@PauloMelo PauloMelo commented Nov 1, 2019

Steps to Reproduce
When opening a box in lazy mode the key of the HiveObject is not set, as it is when the object is opened normally.

In the code Sample bellow it shows:
0 1
null 2

Code sample

import 'dart:io';

import 'package:hive/hive.dart';

class Test extends HiveObject {
  final int id;

  Test (;

class TestAdapter extends TypeAdapter<Test> {
  Test read(BinaryReader reader) {
    var numOfFields = reader.readByte();
    var fields = <int, dynamic>{
      for (var i = 0; i < numOfFields; i++) reader.readByte():,
    return Test(
      fields[0] as int,

  void write(BinaryWriter writer, Test obj) {

void main() async {
    Hive.registerAdapter(TestAdapter(), 0);

    var memBox = await Hive.openBox('normalBox');
    await memBox.add(Test(1));

    var lazyBox = await Hive.openBox('lazyBox', lazy: true) as LazyBox;
    await lazyBox.add(Test(2));

    var obj1 = memBox.getAt(0);
    print("${obj1.key} ${}");

    var obj2 = await lazyBox.getAt(0);
    print("${obj2.key} ${}");


  • Platform: iOS, Android, Mac
  • Flutter version: 1.10.15
  • Hive version: 1.1.1

This comment has been minimized.

Copy link

@leisim leisim commented Nov 1, 2019

Thanks for reporting!

@leisim leisim closed this in b234dec Nov 4, 2019

This comment has been minimized.

Copy link

@leisim leisim commented Nov 4, 2019

Fix will be published with v1.2.0

@leisim leisim added this to the 1.2.0 milestone Nov 4, 2019
leisim added a commit that referenced this issue Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.