isar / isar/hive

Facing "RangeError: Not enough bytes available." When i try to get values from Hive db

Open
#1,187 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

I have a flutter application that send a type to a db in Hive and in my adapter I have the methods read and write to all my variables. The problem is with this variable:

```
@HiveField(5)
String? imoString;
```
This is the line responsible to read the variable in adapter:

`model.imoString = reader.readString();`

and this one is to write:

`writer.writeString(model.imoString ?? "");`

I am 100% sure that I'm saving the variable correctly (with the type string and the value as the value the user wrote in screen) because I can print it in write method. But when I reload the app and the method get from db is called I face this error pointing to the line `model.imoString = reader.readString();`:

>Unhandled Exception: RangeError: Not enough bytes available.

What can I do?

I tried to read with reader.read but it didnt work as well
Obs: the variables are in the right sequence in read and write methods

**EDIT**
I figured out that if I comment the first item of this adapter in both read and write it works.. this first element is another model with its own adapter (it has a lot of variables)

**Version**
- Platform: Android
- Flutter version: 3.7.8
- Hive version: 2.2.3

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Android failure with Flutter 3.7.8 and Hive 2.2.3, then inspect the adapter's read and write methods in the order shown. Pay particular attention to the first nested model and its adapter, since commenting it out changes the result. Done means the stored model can be read without a RangeError and all fields retain their values.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
database, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.