Questions tagged [flutter-hive]

Use this tag when the question is related to the key-value database written in Dart, in combination with a project written in Flutter.

Summary

Hive is a key-value database written in pure Dart.

The data are arranged in boxes, which can also be encrypted for the storage of sensitive data. The box must be opened before use.

Useful Links

380 questions
4
votes
1 answer

type 'Null' is not a subtype of type 'classname' when using Hive in flutter

I am writing a little code in flutter where I am using Hive. this is the code import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:hive_flutter/hive_flutter.dart'; …
Mufasa
  • 63
  • 5
4
votes
2 answers

Can not retrieve data from Hive after application restart

Everything works fine until I restart the app (close the app and open it) and can not see previously saved data, but if I check the box status it is opened and empty. Am I doing something wrong? Running on real device Xiaomi Redmi 4A (actually the…
1encore
  • 394
  • 4
  • 15
4
votes
0 answers

Implement freezed with Hive and inheritance

I have read the documentation but still not able to understand how it works with polymorphism. See the example code I wish to achieve: abstract class BaseUser extends HiveObject { @HiveField(1) final String name; BaseUser({required…
4
votes
2 answers

How to open a Flutter .hive file from Hive in Android Studio

Can someone please explain how to open the .hive files generated by Flutter Hive when you create a Box and add to it? Within my application, the files are stored as name.hive files. I have tried opening them as JSON/XML/plain text but nothing seems…
mav91
  • 165
  • 2
  • 14
4
votes
0 answers

How to use nested class eachother with hive?

Hello I have three nested classes, I want it to store them in box which provided by hive package, I inserted some codes but I dont know is this the true way, How can I store them, can someone help me ? @HiveType(typeId : 1) class CategoryModel…
ygzkrmtc
  • 97
  • 7
4
votes
1 answer

Flutter: fields of an object added to a Hive box returns null after app restart

I'm creating an app with Flutter and Hive but I'm not familiar with it yet. I need to have an initial account in it, so I've made a Hive box for that and I'm trying to save an account object in that box. I check adding with prints and it saved the…
4
votes
8 answers

I get a weird error when trying to initialize Hive

Error: Unhandled Exception: HiveError: You need to initialize Hive or provide a path to store the box. Essentially I have these in my dependencies so everything should be good. hive: ^1.4.4+1 hive_flutter: ^0.3.1 path_provider: ^1.6.27 I also…
user13653605
4
votes
3 answers

HiveError: The box "user" is already open and of type Box

I'm trying to use Hive inside flutter Mobx, after checking user data in Hive I switched to another screens such as HomeView or Intro main.dart: Future main() async { ... final appDocumentDirectory = await…
DolDurma
  • 15,753
  • 51
  • 198
  • 377
4
votes
1 answer

Flutter how to cast the model object to another model to save it to HIVE

I have an API response and parsed it using ProductsModel and I am trying to save it to my local storage using Hive and I have different model called LocalProductsModel. How can I cast the response ProductsModel to LocalProductsModel? I used…
aJaysanity
  • 165
  • 1
  • 5
  • 13
4
votes
1 answer

Unit Testing hive abstraction layer

So I created a simpler level of abstraction to use Hive into my Flutter app. This should be the central point, where all hive boxes are administrated and accessed. Since e.g. getApplicationDocumentsDirectory is not available during testing, how can…
Pris0n
  • 350
  • 1
  • 5
  • 24
4
votes
2 answers

Flutter Hive: make multiple openBox

I'm using Hive to make simple CRUD; in Hive Doc about open box we can declare like this: var box = await Hive.openBox('testBox'); My question: is it possible to make multiple openBox? I want something like this: Future _openBox() async { var…
Zeffry Reynando
  • 3,445
  • 12
  • 49
  • 89
3
votes
1 answer

Create hive object with auto increment integer value

How to create hive object that includes an id field with auto increment integer value? This is my hive object class and id always is -1. How should I fix it? import 'package:hive_flutter/adapters.dart'; part 'reminder.g.dart'; @HiveType(typeId :…
Ghazal
  • 123
  • 2
  • 9
3
votes
1 answer

How to listen to a specific key/value changes in Hive flutter

I have added a new key/value pair inside my Hive box : await Hive.box("myBox").put("myKey", "myValue"); And I have a specific method, let's call it specificMethod(), that I want to execute every time I change the value of that key or to get…
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
3
votes
2 answers

How to store data after 24 hours in flutter? / How to update UI after some time when app is closed/killed in flutter?

I am making an app with flutter. I want to store data after 24 hours and update UI in app. I try with Timer.periodic() but it does not count the time when app is close. It only works when the application is open. Is it possible to execute a function…
Sania Developer
  • 130
  • 1
  • 9
3
votes
3 answers

Flutter Hive store color

I need to store colour in my Hive database to retrieve in my eCommerce Application, it gave me the error below saying that I need to make an adapter, can anyone tell me how to make a colour adapter? part 'items_model.g.dart'; @HiveType(typeId:…
1 2
3
25 26