Retrieve data in Hive
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
I storing list into hive using below code
```
@override
Future saveProperty(List? propertyEntity) async {
try {
final invoiceBox = await Hive.openLazyBox(_propertyBox);
await invoiceBox.put('list', propertyEntity);
} on CacheException catch (e) {
throw CacheException(e.message);
}
}
```
When retrieve, I use get method
```
@override
Future?> getPropertiesList() async {
try {
final propertiesBox = await Hive.openLazyBox(_propertyBox);
if (propertiesBox.isEmpty) return [];
var list = await propertiesBox.get('list');
if (list == null) return [];
return list.cast();
} on CacheException catch (e) {
throw CacheException(e.message);
}
}
```
But if I want to get a specific item, why it will return two items? I thought it should return items with specific index only?
```
@override
Future getPropertyDetails() async {
try {
final propertiesBox = await Hive.openLazyBox(_propertyBox);
var propertyEntity = await propertiesBox.getAt(0); // this is the Listview's index
debugPrint(propertyEntity.toString());
} on CacheException catch (e) {
throw CacheException(e.message);
}
}
```
**Output**
`
[Instance of 'PropertiesEntity', Instance of 'PropertiesEntity']`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Hive.openLazyBox, get, and getAt(0) calls shown in the issue, then consult the LazyBox API documentation and reproduce the stored value and retrieval path. Determine whether the expected outcome is a code change or an explanation of the retrieval behavior; done means a confirmed, documented resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100