PlaceBloc constructor

PlaceBloc({
  1. required PlaceRepository? repository,
})

Constructor to initialize the bloc with the repository instance.

Implementation

PlaceBloc({required this.repository}) : super(const PlaceState()) {
  // Handle events:

  // Event for requesting a place search with a new query string.
  on<RequestedFindPlace>((event, emit) async {
    await _find(emit, state, event.queryString);
  });

  // Event for retrying the previous place search.
  on<RetriedFindPlace>((event, emit) async {
    await _find(emit, state, state.queryString);
  });

  // Event for requesting to show the search places field.
  on<RequestedShowSearchPlacesField>((event, emit) {
    emit(state.copyWith(isShow: true));
  });

  // Event for requesting to hide the search places field.
  on<RequestedHideSearchPlacesField>((event, emit) {
    emit(state.copyWith(isShow: false));
  });

  // Event for toggling the visibility of the search places field.
  on<ToggledSearchPlacesVisibility>((event, emit) {
    if (state.isShow) {
      add(RequestedHideSearchPlacesField());
    } else {
      add(RequestedShowSearchPlacesField());
    }
  });
}