Get element by key won't work with keyComparator
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
Once I open a box using `keyComparator` functions like `Hive.box(shoppingListBox).get(id)` and `Hive.box(shoppingListBox).containsKey(id)` won't work.
After removing `keyComparator` when opening a box it works fine.
**Code sample**
```dart
const shoppingListBox = 'shoppingListBox';
await Hive.openBox(shoppingListBox, keyComparator: (a, b) => -1); //DESC order
final id = const Uuid().v4();
await Hive.box(shoppingListBox).put(id, ShoppingList('Item name', [], DateTime.now()));
final shoppingList = Hive.box(shoppingListBox).get(id); //returns null
final shoppingListExists = Hive.box(shoppingListBox).containsKey(id); //returns false
//shopping_list.dart
@HiveType(typeId: 0)
class ShoppingList extends HiveObject {
@HiveField(0)
String name;
@HiveField(1)
List products;
@HiveField(2)
DateTime? dateAdded;
ShoppingList(this.name, this.products, this.dateAdded);
}
```
**Version**
- Platform: Mac
- Flutter version: 3.0.4
- Hive version: 2.2.3
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the sample with Hive.openBox using keyComparator, then exercise Box.get and Box.containsKey with the inserted key. Trace the lookup path from those entry points; done means both lookups return the inserted ShoppingList while the comparator is enabled, with regression coverage for each call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100