Last active
September 30, 2022 17:54
-
-
Save subramanian42/6aee772ca0640e82491c0ed51d32ad60 to your computer and use it in GitHub Desktop.
music_player_bloc
This file contains hidden or 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 'package:flutter_bloc/flutter_bloc.dart'; | |
part 'music_player_state.dart'; | |
part 'music_player_event.dart'; | |
class MusicPlayerBloc extends Bloc<MusicPlayerEvent, MusicPlayerState> { | |
MusicPlayerBloc({bool isPlaying = false}) : super(InitialState(isPlaying)) { | |
_playMusic = isPlaying; | |
on<PlayPauseButtonPressed>(_handlePlay); | |
on<PreviousTrackButtonPressed>(_handlePreviousTrack); | |
on<NextTrackButtonPressed>(_handleNextTrack); | |
} | |
late bool _playMusic; | |
void _handlePlay( | |
PlayPauseButtonPressed event, Emitter<MusicPlayerState> emit) { | |
_playMusic = !_playMusic; | |
emit(MusicStatusUpdated(_playMusic)); | |
} | |
void _handlePreviousTrack( | |
PreviousTrackButtonPressed event, Emitter<MusicPlayerState> emit) { | |
emit(NavigateToPreviousTrack(_playMusic)); | |
} | |
void _handleNextTrack( | |
NextTrackButtonPressed event, Emitter<MusicPlayerState> emit) { | |
emit(NavigateToNextTrack(_playMusic)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment