Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bloc): make onChange and addError protected #3071

Merged
merged 2 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/bloc/lib/src/bloc_base.dart
Expand Up @@ -122,13 +122,15 @@ abstract class BlocBase<State>
///
/// * [BlocObserver] for observing [Cubit] behavior globally.
///
@protected
@mustCallSuper
void onChange(Change<State> change) {
// ignore: invalid_use_of_protected_member
_blocObserver?.onChange(this, change);
}

/// Reports an [error] which triggers [onError] with an optional [StackTrace].
@protected
@mustCallSuper
@override
void addError(Object error, [StackTrace? stackTrace]) {
Expand Down
1 change: 1 addition & 0 deletions packages/bloc/test/bloc_test.dart
Expand Up @@ -1358,6 +1358,7 @@ void main() {
OnExceptionBloc(
exception: expectedError,
onErrorCallback: (Object _, StackTrace __) {},
// ignore: invalid_use_of_protected_member
)..addError(expectedError, StackTrace.current);
}, (Object error, StackTrace stackTrace) {
expect(error, equals(expectedError));
Expand Down
1 change: 1 addition & 0 deletions packages/bloc/test/cubit_test.dart
Expand Up @@ -54,6 +54,7 @@ void main() {
errors.add(error);
stackTraces.add(stackTrace);
},
// ignore: invalid_use_of_protected_member
)..addError(expectedError, expectedStackTrace);

expect(errors.length, equals(1));
Expand Down