I'm trying to make a flutter app from a guide, to an updated version with newer BloC version but, i've trouble with the changes from the old version to the new version...
First, here is the error i got when i try to press "play" on my application at this stage:
Bad state: add(PlayerEvent) was called without a registered event handler. Make sure to register a handler via on((event, emit) {...})
For what i can understand, this is because mapEventToState is deprecated and from BloC 8.0.1, i've tried to make the change by myself but, i'm a beginner and i've trouble understanding how i should do it.
Here is my actual code who is now deprecated
class PlayBloc extends Bloc<PlayEvent, PlayState>{
final PlayerControl radioPlayer;
PlayBloc({required this.radioPlayer}) : assert(radioPlayer != null),super(isPausedState());
@override //Déprécié
PlayState get initialState => isPausedState();
@override
Stream<PlayState> mapEventToState(PlayEvent event) async* {
if(event is PlayerEvent){
yield isPlayingState();
await radioPlayer.play(url: event.url);
}
else if(event is StopEvent){
yield isPausedState();
await radioPlayer.stop();
}
}
}
could explain to me how to transform this? I tried following the solution proposed here: Flutter bloc migration due to mapEventToState is not working
but I have trouble understanding the changes that have been made..
Thank You
EDIT : Tried again to change it into BloC 8.0 standard, still no luck, it throws an error on "on(mapEventToState)"
The argument type 'Future Function(PlayerEvent)' can't be assigned to the parameter type 'FutureOr Function(PlayerEvent, Emitter)'. (Documentation)
PlayBloc({required this.radioPlayer}) : assert(radioPlayer != null),super(isPausedState()){
on<PlayerEvent>(mapEventToState);
}
//@override //Déprécié
//PlayState get initialState => isPausedState();
Future<void> mapEventToState (
PlayerEvent event
) async {
if (event is PlayerEvent) {
if (state is isPausedState) {
await radioPlayer.play(url: event.url);
emit(isPlayingState());
} else if (state is isPlayingState) {
await radioPlayer.stop();
emit(isPausedState());
}
}
}