Skip to content

Commit faada70

Browse files
authored
refactor(bloc): use Object.hashAll (#4310)
1 parent 117d2ec commit faada70

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

packages/bloc/lib/src/change.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Change<State> {
2424
nextState == other.nextState;
2525

2626
@override
27-
int get hashCode => currentState.hashCode ^ nextState.hashCode;
27+
int get hashCode => Object.hashAll([currentState, nextState]);
2828

2929
@override
3030
String toString() {

packages/bloc/lib/src/transition.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class Transition<Event, State> extends Change<State> {
2727
nextState == other.nextState;
2828

2929
@override
30-
int get hashCode {
31-
return currentState.hashCode ^ event.hashCode ^ nextState.hashCode;
32-
}
30+
int get hashCode => Object.hashAll([currentState, event, nextState]);
3331

3432
@override
3533
String toString() {

packages/bloc/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ topics: [bloc, state-management]
99
funding: [https://github.com/sponsors/felangel]
1010

1111
environment:
12-
sdk: ">=2.12.0 <4.0.0"
12+
sdk: ">=2.14.0 <4.0.0"
1313

1414
dependencies:
1515
meta: ^1.3.0

packages/bloc/test/blocs/async/async_event.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AsyncEvent {
1313
other is AsyncEvent && runtimeType == other.runtimeType;
1414

1515
@override
16-
int get hashCode => runtimeType.hashCode;
16+
int get hashCode => Object.hashAll([runtimeType]);
1717

1818
@override
1919
String toString() => 'AsyncEvent';

packages/bloc/test/blocs/async/async_state.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class AsyncState {
4343
isSuccess == other.isSuccess;
4444

4545
@override
46-
int get hashCode =>
47-
isLoading.hashCode ^ hasError.hashCode ^ isSuccess.hashCode;
46+
int get hashCode => Object.hashAll([isLoading, hasError, isSuccess]);
4847

4948
@override
5049
String toString() =>

packages/bloc/test/transition_test.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CounterEvent extends TransitionEvent {
2525
eventData == other.eventData;
2626

2727
@override
28-
int get hashCode => eventData.hashCode;
28+
int get hashCode => Object.hashAll([eventData]);
2929
}
3030

3131
class CounterState extends TransitionState {
@@ -41,7 +41,7 @@ class CounterState extends TransitionState {
4141
count == other.count;
4242

4343
@override
44-
int get hashCode => count.hashCode;
44+
int get hashCode => Object.hashAll([count]);
4545
}
4646

4747
void main() {
@@ -78,7 +78,7 @@ void main() {
7878
const change = Change<int>(currentState: 0, nextState: 1);
7979
expect(
8080
change.hashCode,
81-
change.currentState.hashCode ^ change.nextState.hashCode,
81+
Object.hashAll([change.currentState, change.nextState]),
8282
);
8383
});
8484
});
@@ -196,9 +196,11 @@ void main() {
196196
);
197197
expect(
198198
transition.hashCode,
199-
transition.currentState.hashCode ^
200-
transition.event.hashCode ^
201-
transition.nextState.hashCode,
199+
Object.hashAll([
200+
transition.currentState,
201+
transition.event,
202+
transition.nextState,
203+
]),
202204
);
203205
});
204206
});

0 commit comments

Comments
 (0)