Created
September 19, 2022 13:32
-
-
Save iBelow/8e92eaebc2cb74f0d017e991f63759b4 to your computer and use it in GitHub Desktop.
bloc observer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:developer'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
class AppObserver extends BlocObserver { | |
@override | |
void onCreate(BlocBase bloc) { | |
super.onCreate(bloc); | |
log('Created $bloc'); | |
} | |
@override | |
void onEvent(Bloc bloc, Object? event) { | |
super.onEvent(bloc, event); | |
log('Event in $bloc: $event'); | |
} | |
@override | |
void onChange(BlocBase bloc, Change change) { | |
super.onChange(bloc, change); | |
log('Changed state in $bloc from ${change.currentState} to ${change.nextState}'); | |
} | |
@override | |
void onTransition(Bloc bloc, Transition transition) { | |
super.onTransition(bloc, transition); | |
log('Transition in $bloc : ${transition.currentState} -> ${transition.nextState}'); | |
} | |
@override | |
void onClose(BlocBase bloc) { | |
super.onClose(bloc); | |
log('Closed $bloc'); | |
} | |
@override | |
void onError(BlocBase bloc, Object error, StackTrace stackTrace) { | |
super.onError(bloc, error, stackTrace); | |
log('Error in $bloc: $error\nStacktrace: $stackTrace'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment