|
| 1 | +import 'dart:developer'; |
| 2 | + |
| 3 | +import 'package:bloc/bloc.dart'; |
| 4 | +import 'package:freezed_annotation/freezed_annotation.dart'; |
| 5 | +import 'package:injectable/injectable.dart'; |
| 6 | +import 'package:music_player/domain/playlist/playlist_service.dart'; |
| 7 | +import 'package:music_player/presentation/playlist/playlist.dart'; |
| 8 | +import 'package:music_player/splash.dart'; |
| 9 | + |
| 10 | +part 'playlist_event.dart'; |
| 11 | +part 'playlist_state.dart'; |
| 12 | +part 'playlist_bloc.freezed.dart'; |
| 13 | + |
| 14 | +@injectable |
| 15 | +class PlaylistBloc extends Bloc<PlaylistEvent, PlaylistState> { |
| 16 | + final PlaylistService _playlistService; |
| 17 | + PlaylistBloc(this._playlistService) : super(PlaylistState.initial()) { |
| 18 | + on<CreatePlylistNames>((event, emit) async { |
| 19 | + final updatedPlaylist = await _playlistService.createPlaylistNames( |
| 20 | + plylstName: event.plylistName); |
| 21 | + log('Bloc finished'); |
| 22 | + emit(state.copyWith(playlistNames: updatedPlaylist)); |
| 23 | + }); |
| 24 | + |
| 25 | + on<MultiSelection>((event, emit) { |
| 26 | + List<String> _selectedPlylst = []; |
| 27 | + _selectedPlylst.addAll(state.selectedList); |
| 28 | + if (state.selectedList.contains(event.selectedPlaylist)) { |
| 29 | + _selectedPlylst.remove(event.selectedPlaylist); |
| 30 | + } else { |
| 31 | + _selectedPlylst.add(event.selectedPlaylist); |
| 32 | + } |
| 33 | + emit(state.copyWith(selectedList: _selectedPlylst)); |
| 34 | + }); |
| 35 | + |
| 36 | + on<UnselectAll>((event, emit) { |
| 37 | + List<String> _emptyList = []; |
| 38 | + emit(state.copyWith(selectedList: _emptyList)); |
| 39 | + }); |
| 40 | + } |
| 41 | +} |
0 commit comments