Issue
Anytime I try to run the following code, it fails to compile, the error is in line 17 of the code, it is in the onError string that is right after Future, looking forward to your response.
import 'package:flutter_bloc/flutter_bloc.dart';
class SimpleBlocObserver extends BlocObserver {
@override
void onEvent(Bloc bloc, Object event) {
print(event);
super.onEvent(bloc, event);
}
@override
void onTransition(Bloc bloc, Transition transition) {
print(transition);
super.onTransition(bloc, transition);
}
@override
Future<void> onError(Cubit cubit, Object error, StackTrace stackTrace) async {
print(error);
super.onError(cubit, error, stackTrace);
}
}
Solution
You can change Cubit cubit
to BlocBase bloc
code snippet
void onError(BlocBase bloc, Object error, StackTrace stackTrace)
// Called whenever an [error] is thrown in any [Bloc] or [Cubit].
/// The [stackTrace] argument may be [StackTrace.empty] if an error
/// was received without a stack trace.
@protected
@mustCallSuper
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {}
code snippet
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
print('onError -- bloc: ${bloc.runtimeType}, error: $error');
super.onError(bloc, error, stackTrace);
}
Answered By - chunhunghan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.