Change in one key-value, cause change in other cloned value for another key
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
I have two different keys in my hive box. At first, I want to put the same data for both, but as the user is using with the app, the values of those keys will change and will be different from each other. The object that I want to use as the value, is like this:
```
@HiveType(typeId: 0)
@JsonSerializable(explicitToJson: true)
class LearningData {
@HiveField(0)
final LevelTest levelTest;
@HiveField(1)
final Map subcategories;
@HiveField(2)
final Map learningWords;
LearningData({required LevelTest? levelTest, required Map? subcategories,
required Map? learningWords})
: levelTest = levelTest ?? LevelTest(know: [], dontKnow: []), learningWords = learningWords ??
{}, subcategories = subcategories ?? {};
LearningData.clone(LearningData learningData): this(levelTest: learningData.levelTest, subcategories: learningData.subcategories, learningWords: learningData.learningWords);
}
```
At first I fill value for both of the keys like this:
```
hiveBox.put(KEY_USER_LEARNING_STATE, learningData);
hiveBox.put(KEY_USER_ONLINE_STATE, LearningData.clone(learningData));
```
The problem is whenever I change the learning data and put in KEY_USER_LEARNING_STATE map, it changes for the other key (KEY_USER_ONLINE_STATE) as well. This causes the bug in my app. What should I do to prevent this?
**Version**
- Platform: Android
- Flutter version: 3.0.5
- Hive version: 2.2.3
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.