isar / isar/hive

[Feature request] change BoxEvent == override from dynamic to Object

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

Description

**Is your feature request related to a problem? Please describe.**
Mocking [BoxEvent] with [mocktail](https://pub.dev/packages/mocktail) is impossible.

This is because you use:
```dart
class BoxEvent {
...

@override
bool operator ==(dynamic other) {
...
}
}
```

Instead of:
```dart
class BoxEvent {
...

@override
bool operator ==(Object other) {
...
}
}
```

If there is a reason I would love to know which, otherwise using `Object` is less restrictive so you should change it to that.

**How to obtain the issue?**

```dart
import 'package:hive/hive.dart';
import 'package:mocktail/mocktail.dart';

class MockBoxEvent extends Mock implements BoxEvent {}
```

The compiler will complain:

> 'Mock.==' ('bool Function(Object)') isn't a valid concrete implementation of 'BoxEvent.==' ('bool Function(dynamic)').

**Describe the solution you'd like**
Change `BoxEvent.==` to the method provided above.

**Describe alternatives you've considered**
Not mocking, it's ok since `BoxEvent` is such a small object but this is not the best experience.

**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: 2.5.2
- Hive version: 2.0.4

**Other remarks**
I noticed that the `key` and `value` attributes of `BoxEvent` are also using `dynamic`. If there is no reason it would be best if you changed them to object. But this is more philosophical than breaking.

Also thanks for the package, it's amazing and saved my a tone of time, I really appreciate it!

I could make a PR to change the `dynamic` to `Object`, I just wanted to check if there was a reason why you used `dynamic` in the first place.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the BoxEvent class and its == operator in the Hive source. Change the operator parameter from dynamic to Object, then verify that the BoxEvent mocking example with mocktail no longer produces the reported implementation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
databases
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.