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

Overview

Fast, Enjoyable & Secure NoSQL Database

GitHub Workflow Status (branch) Codecov branch Pub Version GitHub

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

Documentation & Samples 📖

If you need queries, multi-isolate support or links between objects check out Isar Database.

Features

  • 🚀 Cross platform: mobile, desktop, browser
  • Great performance (see benchmark)
  • ❤️ Simple, powerful, & intuitive API
  • 🔒 Strong encryption built in
  • 🎈 NO native dependencies
  • 🔋 Batteries included

Getting Started

Check out the Quick Start documentation to get started.

Usage

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

var box = Hive.box('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.

@HiveType(typeId: 0)
class Person extends HiveObject {

  @HiveField(0)
  String name;

  @HiveField(1)
  int age;
}

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

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

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

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

person.age = 30;
person.save();

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 and initializing Hive, you can use Hive in your project:

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

class SettingsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder(
      valueListenable: Hive.box('settings').listenable(),
      builder: (context, box, widget) {
        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.

Benchmark

1000 read iterations 1000 write iterations
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.

The benchmark was performed on a Oneplus 6T with Android Q. You can run the benchmark yourself.

*Take this benchmark with a grain of salt. It is very hard to compare databases objectively since they were made for different purposes.

Licence

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

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • The future of Hive

    The future of Hive

    TLDR: Hive 2.0 will be rewritten in Rust to get amazing performance, multithreaded queries, read and write transactions, and super low memory usage. The code will work 1:1 in the browser.

    Situation

    I have thought a long time how to correctly implement queries in Hive and I have come to the conclusion that it is not possible with the current architecture. I have reviewed many projects on GitHub which use Hive and most of them have to create their own suboptimal workaround for queries. Apart from queries, Hive has another problem: Dart objects use much RAM. Since Hive currently keeps at least the keys in RAM, you can hit the OS limit of mobile devices quite fast.

    I also created polls some time ago on the Hive documentation page and there were two very strong takeaways:

    1. Queries are something almost every user wants
    2. An overwhelming majority (86%) of users don't mind breaking changes

    Idea

    So here is what I have come up with: I will completely rewrite Hive in Rust. I will use the strengths of the old implementation (like auto migration) and fix the issues. On the VM, Hive will use LMDB as backend and on the Browser IndexedDB. The VM implementation will provide the same features as IndexedDB to allow easy code sharing. The two main goals of Hive will stay the same: Simplicity and Performance.

    I have a small prototype and the performance is amazing. LMDB has to be some kind of black magic.

    Sample

    Here is how it is going to work:

    The model definition is very similar to current models:

    @HiveType(typeId: 0)
    class Person {
      @Primary
      int id;
    
      @HiveField(fieldId: 0)
      @Index(unique: false)
      String name;
    
      @HiveField(fieldId: 1)
      int age;
    }
    

    Hive will then generate extension methods so you can write the following query:

    var box = Hive.openBox<Person>('persons');
    box
      .query()
      .where()
      .nameEquals('David')
      .or()
      .nameStartsWith('Lu')
      .filter()
      .ageBetween(18, 50)
      .sortedByAge()
    

    where() vs filter()

    The difference between where() and filter() is that where() uses an index and filter() needs to test each of the resulting elements. Normally a database figures out when to use an index itself but Hive will provide you the option to customize.

    There are multiple reasons for that:

    1. This code will work 1:1 with IndexedDB
    2. You know your data best and can choose the perfect index
    3. The database code will be significantly easier

    Things to figure out

    • How can auto-updating queries be implemented efficiently?
    • What are the restrictions for shipping binaries on iOS?
    • Should there still be a key-value store?

    Blocking Issues (pls upvote)

    • dart-lang/sdk#37022
    • dart-lang/sdk#37355
    • flutter/flutter#46887

    Other issues

    • WebAssembly/reference-types#61

    For existing apps using Hive 1.x:

    I will continue to keep a Hive 1.x branch for bugfixes etc.

    What do you think?

    opened by simc 148
  • Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.

    Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.

    hive version: "1.4.0+1" This happen when my app crash and restart immediately by android system

    E/flutter (32001): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.
    E/flutter (32001): #0      BinaryReaderImpl.readFrame 
    package:hive/…/binary/binary_reader_impl.dart:244
    E/flutter (32001): #1      FrameHelper.framesFromBytes 
    package:hive/…/binary/frame_helper.dart:15
    E/flutter (32001): #2      FrameIoHelper.framesFromFile 
    package:hive/…/io/frame_io_helper.dart:36
    E/flutter (32001): <asynchronous suspension>
    E/flutter (32001): #3      StorageBackendVm.initialize 
    package:hive/…/vm/storage_backend_vm.dart:72
    E/flutter (32001): <asynchronous suspension>
    E/flutter (32001): #4      BoxBaseImpl.initialize 
    package:hive/…/box/box_base_impl.dart:82
    E/flutter (32001): #5      HiveImpl._openBox 
    package:hive/src/hive_impl.dart:85
    E/flutter (32001): <asynchronous suspension>
    E/flutter (32001): #6      HiveImpl.openBox 
    package:hive/src/hive_impl.dart:106
    E/flutter (32001): #7      HiveConfigBox.open 
    package:liaobei/hive_liaobei/hive_config_box.dart:28
    E/flutter (32001): #8      HiveLiaobeiManager.openUserBox 
    package:liaobei/hive_liaobei/hive_liaobei_manager.dart:80
    E/flutter (32001): <asynchronous suspension>
    E/flutter (32001): #9      main 
    package:liaobei/main.dart:75
    E/flutter (32001): <asynchronous suspension>
    E/flutter (32001): #10     _runMainZoned.<anonymous closure>.<anonymous closure>  (dart:ui/hooks.dart:239:25)
    E/flutter (32001): #11     _rootRun  (dart:async/zone.dart:1126:13)
    E/flutter (32001): #12     _CustomZone.run  (dart:async/zone.dart:1023:19)
    E/flutter (32001): #13     _runZoned  (dart:async/zone.dart:1518:10)
    E/flutter (32001): #14     runZoned  (dart:async/zone.dart:1502:12)
    E/flutter (32001): #15     _runMainZoned.<anonymous closure>  (dart:ui/hooks.dart:231:5)
    E/flutter (32001): #16     _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:307:19)
    E/flutter (32001): #17     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:174:12)
    
    bug help wanted 
    opened by daibao520 101
  • Unhandled Exception: HiveError: This is an internal error.

    Unhandled Exception: HiveError: This is an internal error.

    Steps to Reproduce No good way to reproduce, ends up just leaving the app in a dead-start state since a box cannot be opened. All i'm running is openBox on startup (which normally causes no problems)

    E/flutter (16607): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: HiveError: This is an internal error. Please open an issue on GitHub and if possible provide a way to reproduce this bug.
    E/flutter (16607): #0      framesFromBytes 
    package:hive/…/binary/frames_from_bytes.dart:22
    E/flutter (16607): #1      FrameIoHelper.framesFromFile 
    package:hive/…/io/frame_io_helper.dart:57
    E/flutter (16607): <asynchronous suspension>
    E/flutter (16607): #2      StorageBackendVm.initialize 
    package:hive/…/backend/storage_backend_vm.dart:109
    E/flutter (16607): <asynchronous suspension>
    E/flutter (16607): #3      BoxBase.initialize 
    package:hive/…/box/box_base.dart:80
    E/flutter (16607): #4      HiveImpl.openBox 
    package:hive/src/hive_impl.dart:76
    E/flutter (16607): <asynchronous suspension>
    E/flutter (16607): #5      MyGuideStorage.init 
    package:app/util/myguide_storage.dart:43
    E/flutter (16607): <asynchronous suspension>
    E/flutter (16607): #6      main 
    package:app/main.dart:21
    E/flutter (16607): #7      _runMainZoned.<anonymous closure>.<anonymous closure>  (dart:ui/hooks.dart:239:25)
    E/flutter (16607): #8      _rootRun  (dart:async/zone.dart:1124:13)
    E/flutter (16607): #9      _CustomZone.run  (dart:async/zone.dart:1021:19)
    E/flutter (16607): #10     _runZoned  (dart:async/zone.dart:1516:10)
    E/flutter (16607): #11     runZoned  (dart:async/zone.dart:1500:12)
    E/flutter (16607): #12     _runMainZoned.<anonymous closure>  (dart:ui/hooks.dart:231:5)
    E/flutter (16607): #13     _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:305:19)
    E/flutter (16607): #14     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:172:12)
    

    Version

    • Platform: Android (Hardware Q) and IOS (simulator latest)
    • Flutter version: v1.10.15-pre.151
    • Hive version: 1.1.0-beta2

    Note that the same issue happens when downgrading back to flutter stable

    Finally, During this installation, I did not clear data (using box.clear) so i dont think it's related to #71

    bug 
    opened by cyberpwnn 61
  • Update Problem

    Update Problem

    Question I am using the hive database for making my items as favorite and show them in a list.

    While clicking a button " favoriteBox.add(Favorite(id, name,place,featuredImage,rating,));"

    if I click that button again then the same data is coming into the list again.

    is there any way to overcome this problem?

    I need to know how can I update a column in the hive.

    I am just showing the item in a list. I just want to update it from my screen.

    question 
    opened by muhammednazil 50
  • deleteFromAllBoxes()

    deleteFromAllBoxes()

    Problem Having the same object referenced across multiple boxes it's possible to save() It will update the object in all the boxes the object it's referenced to. But if you delete() the object it only deletes from the box you are referencing.

    If you have something like

    Fruit (box)
    -String name
    
    Basket (box)
    -List<Fruit> items
    

    If you add the object to both Box, you can have edit the fruit name from any box, but if you can't delete the object from all boxes.

    In database this can be expected behavior or not.

    Feature Request Have a alternative deleteFromAllBoxes()

    enhancement 
    opened by peekpt 43
  • Migrate hive to dart nnbd

    Migrate hive to dart nnbd

    For now, package:hive was migrated, and every test passes, but there are some hacks on the test's codegen and package:crypto and package:mockito have been overriden with git versions which were not published on pub.dev. The tests also depend on the legacy package:dartx and package:pointycastle, so they can only be ran with --no-sound-null-safety.

    The release is blocked until at least package:crypto has an published non-nullable version.

    Ill start working on the hive_generator, as hive needed to be migrated first because it is an direct dependency of the packages which would use the generator.

    enhancement 
    opened by KalilDev 31
  • Make Hive working with @immutable class

    Make Hive working with @immutable class

    @leisim Hi there! It will be awesome to get this awesome plugin Freezed working with immutable models, so we can have immutable model that can be generated and stored directly in Hive database.

    cc: @rrousselGit

    enhancement 
    opened by peekpt 30
  • DateTimeAdapter don't take timezone in consideration

    DateTimeAdapter don't take timezone in consideration

    Steps to Reproduce DateTime fields are saved used local DateTime. My data is synced to a server which will restore the data on a phone change/reinstall. If the user is in a different timezone, all times are wrong when restoring the database.

    The DateTimeAdapter should be writer.writeInt(obj.toUtc).millisecondsSinceEpoch) and DateTime.fromMillisecondsSinceEpoch(micros, isUtc: true).toLocal().

    Version

    • Platform: iOS, Android, Mac, Windows, Linux, Web
    • Flutter version: [e.g. 1.5.4]
    • Hive version: [e.g. 0.5.0]
    problem 
    opened by JCKodel 28
  • HiveError: Cannot read, unknown typeId: 38. Did you forget to register an adapter?

    HiveError: Cannot read, unknown typeId: 38. Did you forget to register an adapter?

    Steps to Reproduce

    Previous code before the issue

    The registration of the adapter:

    registerAdapter(ShelfAdapter());
    registerAdapter(ShelfProductAdapter());
    

    My Models + Adapter:

    @HiveType(typeId: 4)
    class Product implements Identifiable {
      @HiveField(0)
      @override
      final String id;
      @HiveField(1)
      final String name;
    
      @HiveField(2)
      final ProductType type;
    
      const Product({
        @required this.id,
        @required this.name,
        @required this.type,
      });
    }
    
    
    part of 'product.dart';
    
    // **************************************************************************
    // TypeAdapterGenerator
    // **************************************************************************
    
    class ProductAdapter extends TypeAdapter<Product> {
      @override
      final typeId = 4;
    
      @override
      Product read(BinaryReader reader) {
        var numOfFields = reader.readByte();
        var fields = <int, dynamic>{
          for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
        };
        return Product(
          id: fields[0] as String,
          name: fields[1] as String,
          type: fields[2] as ProductType,
        );
      }
    
      @override
      void write(BinaryWriter writer, Product obj) {
        writer
          ..writeByte(3)
          ..writeByte(0)
          ..write(obj.id)
          ..writeByte(1)
          ..write(obj.name)
          ..writeByte(2)
          ..write(obj.type);
      }
    }
    
    part 'product_type.g.dart';
    
    @HiveType(typeId: 4)
    class ProductType {
    
      @HiveField(0)
      final int value;
    
      const ProductType(this.value);
    }
    
    
    part of 'product_type.dart';
    
    // **************************************************************************
    // TypeAdapterGenerator
    // **************************************************************************
    
    class ProductTypeAdapter extends TypeAdapter<ProductType> {
      @override
      final typeId = 4;
    
      @override
      ProductType read(BinaryReader reader) {
        var numOfFields = reader.readByte();
        var fields = <int, dynamic>{
          for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
        };
        return ProductType(fields[0] as int);
      }
    
      @override
      void write(BinaryWriter writer, ProductType obj) {
        writer
          ..writeByte(1)
          ..writeByte(0)
          ..write(obj.value);
      }
    }
    

    So far, so good. But I want to remove the child object / adapter because we don't need it from now on. So let's completely remove the ProjectType and the ProjectTypeAdapter.

    And not the App is crashing with the following Issue:

    HiveError: Cannot read, unknown typeId: 38. Did you forget to register an adapter?

    After a complete new installation everything is working fine.

    Version

    • Platform: iOS, Android
    • Flutter version: 1.17.2 • channel stable
    • Package versions:
      • hive: ^1.4.1+1
      • hive_flutter: ^0.3.0+2
    enhancement 
    opened by stefanschaller 26
  • Help needed: New documentation

    Help needed: New documentation

    A good documentation is crucial for a library. I started working on a new version and would love to get some help from you guys. If you have an idea of how to improve the docs, please comment below or create a pull request in the docs repository.

    The new documentation also allows live code.

    You can find it here: newdocs.hivedb.dev

    documentation help wanted 
    opened by simc 25
  • HiveError: Cannot read, unknown typeId: 32. Did you forget to register an adapter?

    HiveError: Cannot read, unknown typeId: 32. Did you forget to register an adapter?

    When I try start the app this error always appears: HiveError: Cannot read, unknown typeId: 32. Did you forget to register an adapter?

    My Hivetype:

    import 'package:flutter/cupertino.dart';
    import 'package:hive/hive.dart';
    
    part 'auth_token_response_model.g.dart';
    
    @HiveType(typeId: 1)
    class  AuthTokenResponseModel {
    
      AuthTokenResponseModel({@required this.accessToken, @required this.refreshToken,  @required this.accessTokenExpirationDateTime,  @required this.idToken,  @required this.tokenType});
    
      @HiveField(0)
      final String accessToken;
      @HiveField(1)
      final String refreshToken;
      @HiveField(2)
      final DateTime accessTokenExpirationDateTime;
      @HiveField(3)
      final String idToken;
      @HiveField(4)
      final String tokenType;
    }
    

    g.dart file:

    part of 'auth_token_response_model.dart';
    // **************************************************************************
    // TypeAdapterGenerator
    // **************************************************************************
    
    class AuthTokenResponseModelAdapter
        extends TypeAdapter<AuthTokenResponseModel> {
      @override
      AuthTokenResponseModel read(BinaryReader reader) {
        var numOfFields = reader.readByte();
        var fields = <int, dynamic>{
          for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
        };
        return AuthTokenResponseModel(
          accessToken: fields[0] as String,
          refreshToken: fields[1] as String,
          accessTokenExpirationDateTime: fields[2] as DateTime,
          idToken: fields[3] as String,
          tokenType: fields[4] as String,
        );
      }
      @override
      void write(BinaryWriter writer, AuthTokenResponseModel obj) {
        writer
          ..writeByte(5)
          ..writeByte(0)
          ..write(obj.accessToken)
          ..writeByte(1)
          ..write(obj.refreshToken)
          ..writeByte(2)
          ..write(obj.accessTokenExpirationDateTime)
          ..writeByte(3)
          ..write(obj.idToken)
          ..writeByte(4)
          ..write(obj.tokenType);
      }
      @override
      int get typeId => 1;
    }
    

    Main:

    await Hive.initFlutter();
        final appDocumentDir = await path_provider.getApplicationDocumentsDirectory();
        Hive.init(appDocumentDir.path);
        Hive.registerAdapter(AuthTokenResponseModelAdapter());
        await HiveService.hiveInit();
    

    hiveInit:

    static Future<Box> hiveInit() async {
        await Hive.openBox('userlogin');
        await Hive.openBox('skipped');
        await  Hive.openBox('lastSearched');
      }
    

    Version

    • Platform: iOS, Android
    • Flutter version: v1.12.13+hotfix.8
    • Hive version: hive: ^1.0.0 hive_flutter: ^0.3.0+2
    problem 
    opened by dominikkeller 24
  • Target of URI hasn't been generated: ''goods.g.dart''. Try running the generator that will generate the file referenced by the URI.

    Target of URI hasn't been generated: ''goods.g.dart''. Try running the generator that will generate the file referenced by the URI.

    I want to try hive implementation. But when i add part 'goods.g.dart' it's return below error.

    Target of URI hasn't been generated: ''goods.g.dart''. Try running the generator that will generate the file referenced by the URI.

    Here is my code:

    import 'package:hive/hive.dart';

    part 'goods.g.dart';

    @HiveType(typeId: 0) class Goods extends HiveObject { @HiveField(0) final String? title; @HiveField(1) final String? type; @HiveField(2) final int? episodes; @HiveField(3) final String? status; @HiveField(4) final String? startDate; @HiveField(5) final String? endDate; @HiveField(6) final String? startingSeason; @HiveField(7) final String? broadcastTime;

    Goods({ this.title, this.type, this.episodes, this.status, this.startDate, this.endDate, this.startingSeason, this.broadcastTime, }); }

    Here is my pubspec.yml

    d``` ependencies: flutter: sdk: flutter

    get: ^4.6.5 dio: ^4.0.6 geocoding: ^2.0.5 flutter_svg: ^1.1.5 grouped_list: ^5.1.2 image_picker: ^0.8.6 carousel_slider: ^4.1.1 cupertino_icons: ^1.0.2 dotted_border: ^2.0.0+2 connectivity_plus: ^3.0.2 google_maps_flutter: ^2.2.1 cached_network_image: ^3.2.2 firebase_auth: ^4.1.2 firebase_core: ^2.2.0 cloud_firestore: ^4.2.0 firebase_messaging: ^14.1.2 firebase_dynamic_links: ^5.0.5 hive: ^2.2.3 hive_flutter: ^1.1.0 mime: ^1.0.2 intl: ^0.17.0 timeago: ^3.3.0 share_plus: ^6.3.0 flutter_typeahead: ^4.1.1 pin_code_text_field: ^1.8.0 geolocator: ^9.0.2 otp_autofill: ^2.1.0 firebase_storage: ^11.0.7 provider: ^6.0.4 flutter_local_notifications: ^13.0.0 fluttertoast: ^8.1.2 bubble: ^1.1.9+1 flutter_native_image: ^0.0.6+1 build_runner: ^2.3.3 json_serializable: ^6.5.4 dev_dependencies: flutter_test: sdk: flutter

    problem 
    opened by maralerdene 0
  • web.indexed_db: is `'read-write'` correct `mode` for `transaction`, or a mistake?

    web.indexed_db: is `'read-write'` correct `mode` for `transaction`, or a mistake?

    Hello,

    In the source code, at ~/hive/backend/js/web_worker.dart, 'read-write' is being passed to IDBDatabase.transaction( function, which is,

    Question Is this behavior correct, or a mistype?

    Thanking you,

    question 
    opened by gintominto5329 2
  • Null error breaks app only in release builds

    Null error breaks app only in release builds

    There are the following error messages on the WEB DevTools console:

    TypeError: null: type 'minified:Ue' is not a subtype of type 'minified:pb<dynamic>'
    main.dart.js:23522     at Object.f (https://app.0byte.app/main.dart.js:4227:3)
    main.dart.js:23522     at Object.aQE (https://app.0byte.app/main.dart.js:4842:18)
    main.dart.js:23522     at iD.b1i [as a] (https://app.0byte.app/main.dart.js:4837:3)
    main.dart.js:23522     at iD.b1w (https://app.0byte.app/main.dart.js:4809:10)
    main.dart.js:23522     at aoM.$1 (https://app.0byte.app/main.dart.js:35328:28)
    main.dart.js:23522     at bm.t (https://app.0byte.app/main.dart.js:34869:19)
    main.dart.js:23522     at ab4.br (https://app.0byte.app/main.dart.js:73079:126)
    main.dart.js:23522     at ab4.br (https://app.0byte.app/main.dart.js:75192:13)
    main.dart.js:23522     at ab4.iR (https://app.0byte.app/main.dart.js:64570:9)
    main.dart.js:23522     at ab4.iR (https://app.0byte.app/main.dart.js:64606:11)
    
    Another exception was thrown: Instance of 'minified:eJ<void>'
    

    There are no issues when running debug. They only appear when using flutter release.

    Found someone with same issue: https://stackoverflow.com/questions/72676504/instance-of-minifiedpdynamic-type-minifiedpdynamic-is-not-a-subtype-o

    Only happens on WEB target AND only when using release builds.

    Steps to Reproduce

    1. Clone https://github.com/gruvw/0byte, git clone https://github.com/gruvw/0byte.git
    2. cd 0byte
    3. git reset --hard 5b751693a0bff45786110e2b491de17302682bea
    4. flutter run --release and select WEB target
    5. Follow steps to reproduce https://github.com/gruvw/0byte/issues/3

    Version

    • Platform: Web (issue is only present on web releases)
    • Flutter version: 3.3.10
    • Hive version: 2.2.3
    problem 
    opened by gruvw 0
  • Error: Expected a value of type 'FutureOr<type>', but got one of type 'type'

    Error: Expected a value of type 'FutureOr', but got one of type 'type'

    Call await function after hot reload/hot restart and after refreshing the page.

    Code sample

    @override
      Future<T?> load<T>({required String table, required String key, T? defaultValue}) async {
        return await Hive.box(table).get(key, defaultValue: defaultValue);
      }
    

    Error log:

    Error: Expected a value of type 'FutureOr<List<String>?>', but got one of type 'List<dynamic>'
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49      throw_
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 99:3        castError
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 452:10  cast
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/classes.dart 193:14     as_FutureOr
    packages/discounts_mobile/data/client/local/hive_local_client.dart 16:5           load
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
    dart-sdk/lib/async/zone.dart 1653:54                                              runUnary
    dart-sdk/lib/async/future_impl.dart 147:18                                        handleValue
    dart-sdk/lib/async/future_impl.dart 766:44                                        handleValueCallback
    dart-sdk/lib/async/future_impl.dart 795:13                                        _propagateToListeners
    dart-sdk/lib/async/future_impl.dart 430:9                                         callback
    dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
    dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15               <fn>
    
    

    Version

    • Platform: Bug on Web, but also works properly on iOS, Android
    • Flutter version: [3.3.10]
    • Hive version: [^2.2.3]
    • Hive Flutter version: [^1.1.0]
    problem 
    opened by abikko 0
  • Hive storage is empty after restarting the flutter app

    Hive storage is empty after restarting the flutter app

    I currently have the problem that my flutter app doesn't get any data from the hive db after the app was restarted. The problem occurred when i updated flutter and dart for an other package (it did work perfectly well before). It seems like it has something to do with the SDK version, but due to another package I can't go lower than 2.18.5 at the moment. Is there a known version issue, or am I facing this problem because of my implementation?

    In the following section you can find the (stripped) code of the main app-widget.

    `import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:json_theme/json_theme.dart'; import 'package:flutter/foundation.dart'; import 'package:uni_links/uni_links.dart';

    bool _initialUriIsHandled = false;

    Future main() async {

    await Hive.initFlutter();

    Hive.registerAdapter(AdminAdapter()); Hive.registerAdapter(AssetAdapter()); Hive.registerAdapter(ConsumeProfileAdapter()); Hive.registerAdapter(conModel.ConsumerAdapter()); Hive.registerAdapter(DepartmentAdapter()); Hive.registerAdapter(FeatureAdapter()); Hive.registerAdapter(TransactionAdapter()); Hive.registerAdapter(UserAdapter());

    runApp( EasyLocalization( supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')], path: 'assets/translations', fallbackLocale: Locale('en', 'US'), child: App(theme: theme, darkTheme: darkTheme), ), ); }

    Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { print("Handling a background message: ${message.messageId}"); }

    class App extends StatefulWidget { final ThemeData theme; final ThemeData darkTheme; const App({super.key, required this.theme, required this.darkTheme});

    @override State createState() => _AppState(); }

    class _AppState extends State { Uri? _initialUri; Uri? _latestUri; Object? _err;

    StreamSubscription? _sub;

    @override void initState() { super.initState(); _handleIncomingLinks(); _handleInitialUri(); }

    @override Future dispose() async { _sub?.cancel(); await Hive.close(); super.dispose(); }

    @override Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider( create: (context) => FunctionNotifyProvider(), ), ChangeNotifierProvider( create: (context) => AuthenticationProvider(), ), ChangeNotifierProvider( create: (context) => SettingsProvider(), ), ChangeNotifierProvider( create: (context) => AppManagement(), ) ], child: Builder( builder: (ctx) { return MaterialApp( localizationsDelegates: context.localizationDelegates, navigatorKey: navigatorKey, key: UniqueKey(), title: 'DEHNapp', locale: context.locale, darkTheme: widget.darkTheme, themeMode: ctx.watch().getThemeMode(), theme: widget.theme, home: MainScreen(_initialUri, _latestUri), routes: { '/about': (ctx) => const AboutScreen(), '/about/licenses': (ctx) => AboutLicensesScreen() }, ); }, ), ); } } `

    Version

    • Platform: iOS, Android, Mac, Windows, Linux, Web
    • Flutter version: 3.3.9
    • Dart: 2.18.5
    • Hive version: 2.2.3
    question 
    opened by el-stoega 0
  • Exception from compact method

    Exception from compact method

    I was running my code to gather some statistics (it wasn't connected with hive) for like an hour and I got this exception which ruined all process: Unhandled exception: FileSystemException: Cannot rename file to 'C:\Users\faufd\Desktop\sh\cpp_native\example\uploadbox-v1.0.hive', path = 'C:\Users\faufd\Desktop\sh\cpp_native\example\uploadbox-v1.0.hivec' (OS Error: Access denied. , errno = 5) #0 _File.rename.<anonymous closure> (dart:io/file_impl.dart:305:9) <asynchronous suspension> #1 StorageBackendVm.compact.<anonymous closure> (package:hive/src/backend/vm/storage_backend_vm.dart:188:7) <asynchronous suspension> #2 BoxBaseImpl.compact (package:hive/src/box/box_base_impl.dart:151:5) <asynchronous suspension> #3 BoxImpl._writeFrames (package:hive/src/box/box_impl.dart:95:5) <asynchronous suspension> I have 2 files in this directory uploadbox-v1.0.hive and uploadbox-v1.0.hivec, compact() method was called on background by hive.

    problem 
    opened by ffdb42 0
Releases(v3.0.0-dev)
  • v3.0.0-dev(Oct 15, 2022)

    What's Changed

    • added the notify parameter to the functions of the public API by @tomassasovsky in https://github.com/hivedb/hive/pull/1019
    • feat: implement Web Worker support by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/1030
    • feat: add .gitignore by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/1035
    • feat: improve BinaryWriter API by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/986
    • Implement fully working StorageBackendMemory by @grieshofer in https://github.com/hivedb/hive/pull/1036
    • feat: store open boxes including collection by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/1038
    • fix: missing TupleBoxKey for opening boxes by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/1041
    • fix(hive_generator): Apply analyzer 5.0.0 or higher by @jukqaz in https://github.com/hivedb/hive/pull/1085

    New Contributors

    • @tomassasovsky made their first contribution in https://github.com/hivedb/hive/pull/1019
    • @grieshofer made their first contribution in https://github.com/hivedb/hive/pull/1036
    • @jukqaz made their first contribution in https://github.com/hivedb/hive/pull/1085

    Full Changelog: https://github.com/hivedb/hive/compare/v2.2.3...v3.0.0-dev

    Source code(tar.gz)
    Source code(zip)
  • v2.2.3(Jun 30, 2022)

    What's Changed

    • fix: Remove print from deleteBoxFromDisk by @krillefear in https://github.com/hivedb/hive/pull/1015
    • feat: made resetAdapters public by @alestiago in https://github.com/hivedb/hive/pull/1014

    New Contributors

    • @krillefear made their first contribution in https://github.com/hivedb/hive/pull/1015
    • @alestiago made their first contribution in https://github.com/hivedb/hive/pull/1014

    Full Changelog: https://github.com/hivedb/hive/compare/v2.2.2...v2.2.3

    Source code(tar.gz)
    Source code(zip)
  • v2.2.1(May 18, 2022)

    What's Changed

    • hive_generator: Update Analyzer version. by @ryojiro in https://github.com/hivedb/hive/pull/969
    • fix: provide fallback backend manager by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/968

    New Contributors

    • @ryojiro made their first contribution in https://github.com/hivedb/hive/pull/969

    Full Changelog: https://github.com/hivedb/hive/compare/v2.2.0...v2.2.1

    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(May 17, 2022)

    What's Changed

    • Upstream FluffyBox patches by @TheOneWithTheBraid in https://github.com/hivedb/hive/pull/956

    New Contributors

    • @TheOneWithTheBraid made their first contribution in https://github.com/hivedb/hive/pull/956

    Full Changelog: https://github.com/hivedb/hive/compare/v2.1.0...v2.2.0

    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Mar 20, 2022)

    What's Changed

    • Do not return uninitialized box by @maRci002 in https://github.com/hivedb/hive/pull/916
    • Support adapter type inheritance by @saibotma in https://github.com/hivedb/hive/pull/927
    • Close uninitialized boxes by @themisir in https://github.com/hivedb/hive/pull/917
    • Support UTF-8 keys by @themisir in https://github.com/hivedb/hive/pull/928

    New Contributors

    • @saibotma made their first contribution in https://github.com/hivedb/hive/pull/927

    Full Changelog: https://github.com/hivedb/hive/compare/v2.0.6...v2.1.0

    Source code(tar.gz)
    Source code(zip)
  • v2.0.6(Feb 24, 2022)

    What's Changed

    • Updated hive_generator analyzer dependency by @NatsuOnFire in https://github.com/hivedb/hive/pull/858
    • Change pedantic to linter and fix warnings by @themisir in https://github.com/hivedb/hive/pull/876
    • Fix: This should not happen. Please open an issue on GitHub. by @maRci002 in https://github.com/hivedb/hive/pull/914

    New Contributors

    • @NatsuOnFire made their first contribution in https://github.com/hivedb/hive/pull/858
    • @maRci002 made their first contribution in https://github.com/hivedb/hive/pull/914

    Full Changelog: https://github.com/hivedb/hive/compare/v2.0.5...v2.0.6

    Source code(tar.gz)
    Source code(zip)
  • v2.0.5(Dec 16, 2021)

    Enhancements

    • Get IndexedDB selectively based on window property - #802
    • Added path parameter to boxExists and deleteBoxFromDisk methods - #776
    • Added flush method to boxes - #852

    Fixes

    • Don't loose track of box objects if init crashes - #846
    Source code(tar.gz)
    Source code(zip)
  • v2.0.4(Jun 20, 2021)

  • v2.0.3(Apr 13, 2021)

  • v2.0.0(Mar 7, 2021)

  • v1.6.0-nullsafety.0(Jan 30, 2021)

  • v1.5.0-pre(Oct 4, 2020)

  • v1.4.4(Aug 20, 2020)

  • v1.4.3(Aug 9, 2020)

  • v1.4.1+1(Feb 26, 2020)

  • v1.4.1(Feb 22, 2020)

    Enhancements

    • Minor performance improvements

    Fixes

    • When a database operation failed, subsequent operations would not be performed

    Other

    • Fixed GitHub homepage path
    Source code(tar.gz)
    Source code(zip)
  • hive_generator_v0.7.0+2(Feb 22, 2020)

  • hive_flutter_v0.3.0+2(Feb 22, 2020)

  • 1.4.0+1(Feb 8, 2020)

  • v1.4.0(Feb 7, 2020)

    Enhancements

    • ~1000% encryption / decryption performance improvement
    • Added option to implement custom encryption algorithm
    • Added box.valuesBetween(startKey, endKey)
    • Allow tree shaking to drop encryption engine if no encryption is used

    Fixes

    • Hive.deleteBoxFromDisk() did not work for boxes with upper-case names

    More

    • Deprecated encryptionKey parameter. Use Hive.openBox('name', encryptionCipher: HiveAesCipher(yourKey)).
    • Dropped pointycastle dependency
    • Dropped path dependency
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Jan 3, 2020)

    Use latest version of hive_generator

    Breaking changes

    • TypeAdapters and @HiveType() now require a typeId
    • Hive.registerAdapter() does not need a typeId anymore.
    • Removed BinaryReader.readAsciiString()
    • Removed BinaryWriter.writeAsciiString()

    Enhancements

    • New documentation with tutorials and live code

    Fixes

    • box.clear() resets auto increment counter

    More

    • Not calling Hive.init() results in better exception
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Dec 22, 2019)

    Use latest version of hive_generator

    Breaking changes

    • Removed the Hive.path getter
    • Removed Hive.openBoxFromBytes() (use the bytes parameter of Hive.openBox() instead)
    • LazyBox and Box now have a common parent class: BoxBase
    • Lazy boxes need to be opened using Hive.openLazyBox()
    • Open lazy boxes can be aquired using Hive.lazyBox()
    • Box name bug resolved (more information below)

    Enhancements

    • Support for relationships, HiveLists (see docs for details)
    • Support for inheritance
    • Lazy boxes can now have a type argument LazyBox<YourModel>
    • Added method to delete boxes without opening them Hive.deleteBoxFromDisk()
    • Added path parameter to open boxes in a custom path
    • Improved documentation

    Fixes

    • HiveObjects have not been initialized correctly in lazy boxes
    • Fixed bug where uppercase box name resulted in an uppercase filename
    • Fixed compaction bug which caused corrupted boxes
    • Fixed bug which did not allow the key 0xFFFFFFFF
    • Fixed bug where not all BoxEvents have been broadcasted

    More

    • Changed type of encryptionKey from Uint8List to List<int>

    Important:

    Due to a bug in previous Hive versions, boxes whose name contains uppercase characters were stored in a file that also contains upper case characters (e.g. 'myBox' -> 'myBox.hive').

    To avoid different behavior on case sensitive file systems, Hive should store files with lower case names. This bug has been resolved in version 1.2.0.

    If your box name contains upper case characters, the new version will not find a box stored by an older version. Please rename the hive file manually in that case.
    This also applies to the web version.

    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Oct 22, 2019)

    Breaking changes

    • object.delete() now throws exception if object is not stored in a box

    Fixes

    • Fixed bug where object.save() would faild on subsequent calls
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0+2(Oct 18, 2019)

  • v1.1.0+1(Oct 17, 2019)

  • v1.1.0(Oct 16, 2019)

    Breaking changes

    • Changed return type of addAll() from List<int> to Iterable<int>.
    • Removed the option to register TypeAdapters for a specific box. E.g. box.registerTypeAdapter().
    • getAt(), putAt(), deleteAt() and keyAt() no longer allow indices out of range.

    Enhancements

    • Added HiveObject
    • Boxes have now an optional type parameter Box<E>
    • Support opening boxes from assets

    Fixes

    • Fixed bug which was caused by not awaiting write operations
    • Fixed bug where custom compaction strategy was not applied
    • Hive now locks box files while they are open to prevent concurrent access from multiple processes

    More

    • Improved performance of putAll(), deleteAll(), add(), addAll()
    • Changed values parameter of addAll() from List to Iterable
    • Improved documentation
    • Preparation for queries
    Source code(tar.gz)
    Source code(zip)
Owner
HiveDB
Hive is a lightweight and blazing fast key-value database written in pure Dart.
HiveDB
A fast, extra light and synchronous key-value storage to Get framework

get_storage A fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and

Jonny Borges 257 Dec 21, 2022
The lightweight and powerful wrapper library for Twitter Ads API written in Dart and Flutter 🐦

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Twitter.dart 2 Aug 26, 2022
Simple and fast Entity-Component-System (ECS) library written in Dart.

Fast ECS Simple and fast Entity-Component-System (ECS) library written in Dart. CPU Flame Chart Demonstration of performance for rotation of 1024 enti

Stanislav 8 Nov 16, 2022
A lightweight and powerful batch library written in Dart

A lightweight and powerful batch library written in Dart. You can easily develop a job schedule and batch program in Dart with this library.

Kato Shinya 24 Dec 13, 2022
Fast math TeX renderer for Flutter written in Dart.

CaTeX is a Flutter package that outputs TeX equations (like LaTeX, KaTeX, MathJax, etc.) inline using a widget and Flutter only - no plugins, no web v

simpleclub 56 Nov 14, 2022
DartMeltySoundFont - a SoundFont synthesizer (i.e. '.sf2' player) written in pure Dart

DartMeltySoundFont DartMeltySoundFont is a SoundFont synthesizer (i.e. '.sf2' player) written in pure Dart. It is a port of MeltySynth (C#, MIT Licens

Chip Weinberger 11 Oct 29, 2022
A simple set of terminal-based arcade games written in pure Dart.

dartcade A simple set of terminal-based arcade games written in pure Dart. Purpose I was developing some simple 2D UI libraries (such as package:gridd

Matan Lurey 7 Dec 7, 2022
SurrealDB client written in pure dart. auto reconnect, typed functions

SurrealDB Client For Dart & Flutter SurrealDB client for Dart and Flutter. Quick Start import 'package:surrealdb/surrealdb.dart'; void main(List<Stri

Duhan BALCI 10 Dec 18, 2022
A flutter plugin to play Youtube Videos without API Key in range of Quality(144p, 240p,360p,480p,720p and 1080p).

Youtube Player Plugin This plugin is discontinued. Please use youtube_player_flutter which is an officially provided way of playing youtube videos, su

Sarbagya Dhaubanjar 120 Nov 13, 2022
Netflix app UI clone using bloc,Rest API and TMDB for API key

netflix_flutter project_using_bloc packages Used flutter_bloc json_serializable get_it dio A few resources to get you started if this is your first Fl

Pranav Pv 16 Nov 25, 2022
A degital diary with key feature of saving your thoughts with image

localstore A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

null 1 Nov 13, 2021
Behruz Hurramov 0 Dec 29, 2021
WIP: generate easy localization key code

Generates translation key code for the easy localization package. Support for json and yaml formats.You can see examples in the assets/ folder. Gettin

null 3 Oct 24, 2022
This is the Zuri Chat Android app project repository handled by TEAM SOCRATES, written with pure Flutter.

Zuri Chat Overview This is the Zuri Chat Android app project repository handled by TEAM SOCRATES, written with pure Flutter. NB: Always contact Team l

Zuri Chat 32 Nov 22, 2022
A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Simplify Equality Comparisons Overview Being able to compare objects in Dart often involves having to override the == operator as well as hashCode. No

Felix Angelov 747 Jan 8, 2023
A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage

A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage

The Github Mafia 17 Dec 24, 2022
How to get the most value from Dart static analysis

This package is deprecated. Before it was deprecated, it was the way to get analysis options matching those used internally at Google. This was useful

Google 324 Nov 4, 2022
How to get the most value from Dart static analysis

This package is deprecated. Before it was deprecated, it was the way to get analysis options matching those used internally at Google. This was useful

Google 324 Nov 4, 2022
dna, dart native access. A lightweight dart to native super channel plugin

dna, dart native access. A lightweight dart to native super channel plugin, You can use it to invoke any native code directly in contextual and chained dart code.

Assuner 14 Jul 11, 2022