Advertisement
rifki_cs29

CategoryFilterBloc

Mar 13th, 2022
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.61 KB | None | 0 0
  1. import 'package:bloc/bloc.dart';
  2. import 'package:equatable/equatable.dart';
  3.  
  4. part 'category_filter_event.dart';
  5. part 'category_filter_state.dart';
  6.  
  7. class CategoryFilterBloc
  8.     extends Bloc<CategoryFilterEvent, CategoryFilterState> {
  9.   Set<String> selectedLocation = {};
  10.   List<String> selectedCategory = [];
  11.   List<String> selectedCondition = [];
  12.   List<String> selectedCourier = [];
  13.   CategoryFilterBloc() : super(CategoryFilterState.initial()) {
  14.     on<OnSelectedLocation>(
  15.       (event, emit) {
  16.         selectedLocation.add(event.location);
  17.         emit(
  18.           state.copyWith(
  19.             isFilter: true,
  20.             selectedLocation: selectedLocation,
  21.           ),
  22.         );
  23.       },
  24.     );
  25.  
  26.     on<UnSelectedLocation>((event, emit) {
  27.       selectedLocation.remove(event.location);
  28.       emit(
  29.         state.copyWith(
  30.           selectedLocation: selectedLocation,
  31.         ),
  32.       );
  33.     });
  34.  
  35.     on<OnSelectedCategory>((event, emit) {
  36.       selectedCategory.add(event.category);
  37.       emit(
  38.         state.copyWith(
  39.           isFilter: true,
  40.           selectedCategory: selectedCategory,
  41.         ),
  42.       );
  43.     });
  44.  
  45.     on<OnSelectedCondition>((event, emit) {
  46.       selectedCondition.add(event.condition);
  47.       emit(
  48.         state.copyWith(
  49.           isFilter: true,
  50.           selectedCondition: selectedCondition,
  51.         ),
  52.       );
  53.     });
  54.  
  55.     on<OnSelectedCourier>((event, emit) {
  56.       selectedCourier.add(event.courier);
  57.       emit(
  58.         state.copyWith(
  59.           isFilter: true,
  60.           selectedCourier: selectedCourier,
  61.         ),
  62.       );
  63.     });
  64.   }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement