isar / isar/hive

Mutating the object returned from Box also mutates data in the box

Open
#537 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

**Question**
I'm currently trying to create a sample todo list app.
My use case:
- When user enters the screen, I get data from the Hive box.
- When the user changes the data from the retrieved box, it also mutates the same data in the Hive box.
- When the app is restarted, only then the data is back.

In the below example:
- I have already created and stored a routineItem in the routine box.
- When I changed the isCompleted boolean, inspecting the box I see that the same routineItem property is also mutated.
- Only when I restart the test/app, the original data(unmutated data) is back.

Please help me with this. Am I doing something wrong?

**Code sample**
```
Hive.init(appDocumentDir.path);
Hive.registerAdapter(RoutineAdapter());
Hive.registerAdapter(RoutineItemAdapter());
Box routineBox = await Hive.openBox('routine');

String date = '2021-1-9';

Routine r = routineBox.get(date);

r.routines[0].isCompleted = true;

print(r.routines[0].isCompleted);

print(routineBox);
```

**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: 1.22.5
- Hive version: 1.4.4+1

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.