Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:bloc/bloc.dart';
- import 'package:equatable/equatable.dart';
- part 'category_filter_event.dart';
- part 'category_filter_state.dart';
- class CategoryFilterBloc
- extends Bloc<CategoryFilterEvent, CategoryFilterState> {
- Set<String> selectedLocation = {};
- List<String> selectedCategory = [];
- List<String> selectedCondition = [];
- List<String> selectedCourier = [];
- CategoryFilterBloc() : super(CategoryFilterState.initial()) {
- on<OnSelectedLocation>(
- (event, emit) {
- selectedLocation.add(event.location);
- emit(
- state.copyWith(
- isFilter: true,
- selectedLocation: selectedLocation,
- ),
- );
- },
- );
- on<UnSelectedLocation>((event, emit) {
- selectedLocation.remove(event.location);
- emit(
- state.copyWith(
- selectedLocation: selectedLocation,
- ),
- );
- });
- on<OnSelectedCategory>((event, emit) {
- selectedCategory.add(event.category);
- emit(
- state.copyWith(
- isFilter: true,
- selectedCategory: selectedCategory,
- ),
- );
- });
- on<OnSelectedCondition>((event, emit) {
- selectedCondition.add(event.condition);
- emit(
- state.copyWith(
- isFilter: true,
- selectedCondition: selectedCondition,
- ),
- );
- });
- on<OnSelectedCourier>((event, emit) {
- selectedCourier.add(event.courier);
- emit(
- state.copyWith(
- isFilter: true,
- selectedCourier: selectedCourier,
- ),
- );
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement